@bendyline/molen-client 0.0.9 → 0.0.10

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 CHANGED
@@ -67,6 +67,7 @@ probe — a pinned backend is what makes a captured frame reproducible.
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
69
  | `./aircraft` | `createAircraftVisual`, `aircraftCameraPose` — animated airframe and instrumented cockpit, the render half of `@bendyline/molen-kernel/aircraft` |
70
+ | `./instruments` | Named signal expressions and reusable wiring for calibrated dials, altimeters, attitude indicators, annunciators and seven-segment readouts; geometry stays in each model |
70
71
  | `./navigation` | `OrbitController`, `FlyController`, `WalkController` + `WalkCollision`, `FollowController`, `NavigationInputSource` (keys, gamepad, pointer gestures) and `createTouchJoystick` — camera navigation for `createViewer` hosts |
71
72
  | `./markers` | `createMarkerLayer`, `composeMarkerImage`, `projectWorldToScreen` — screen-sized, ground-snapped, pickable world markers such as photo pins |
72
73
  | `./audio` | `createAudioLayer`, `AudioDirector`, `WebAudioBackend`, `loadPackSoundbanks`, `attachAutoplayUnlock` — plays sound banks and a scene's `audioEnvironment`/`audioSource`/`audioZone` rules and `molen.audio.*` events; three-free at runtime, so the director also runs in Node |
@@ -1,5 +1,5 @@
1
- import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-DVlLyP-w.mjs";
2
- import { a as VehicleCameraPose, i as VehicleCameraOptions, n as VehicleInteriorVisual } from "./vehicle-interior-GWcXnvXS.mjs";
1
+ import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
2
+ import { a as VehicleCameraPose, i as VehicleCameraOptions, n as VehicleInteriorVisual } from "./vehicle-interior-BgcC750p.mjs";
3
3
  import { AircraftInputData, AircraftSpec, AircraftStateData } from "@bendyline/molen-schema";
4
4
  import * as THREE from "three";
5
5
 
@@ -9,7 +9,7 @@ interface AircraftVisual {
9
9
  interior?: VehicleInteriorVisual;
10
10
  /** The spec's exterior `animation` bindings (gear legs and doors, control surfaces). */
11
11
  animation?: ModelSignalVisual;
12
- update(state: AircraftStateData, input: AircraftInputData, altitude: number, signals?: ModelSignals): void;
12
+ update(state: AircraftStateData, input: AircraftInputData, altitude: number, signals?: ModelSignals, timeSeconds?: number): void;
13
13
  dispose(): void;
14
14
  }
15
15
  /**
package/dist/aircraft.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as createModelSignalVisual } from "./model-signals-Dp5OV-Y0.mjs";
2
- import { t as createVehicleInteriorVisual } from "./vehicle-interior-vJQsRLQy.mjs";
1
+ import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
2
+ import { t as createVehicleInteriorVisual } from "./vehicle-interior-DfpZwWEh.mjs";
3
3
  import * as THREE from "three";
4
4
  //#region src/aircraft.ts
5
5
  /**
@@ -29,7 +29,7 @@ function createAircraftVisual(model, spec) {
29
29
  object: model,
30
30
  interior,
31
31
  animation,
32
- update(state, input, altitude, signals) {
32
+ update(state, input, altitude, signals, timeSeconds) {
33
33
  const gear = state.gearPosition ?? Number(input.gear);
34
34
  const flaps = state.flapPosition ?? Number(input.flaps);
35
35
  for (const binding of spec.visual.rotors) {
@@ -44,15 +44,43 @@ function createAircraftVisual(model, spec) {
44
44
  turn(spec.visual.controlStick.node, spec.visual.controlStick.rollAxis, input.roll * .22);
45
45
  }
46
46
  if (interior === void 0 && spec.visual.collective !== void 0) turn(spec.visual.collective.node, spec.visual.collective.axis, input.power * spec.visual.collective.multiplier);
47
+ const engineSignals = Object.create(null);
48
+ for (const engine of spec.engines ?? []) {
49
+ const reading = state.engines?.[engine.id];
50
+ const prefix = `engines.${engine.id}.`;
51
+ engineSignals[`${prefix}rpmNormalized`] = reading?.rpm;
52
+ engineSignals[`${prefix}rotorRpm`] = reading === void 0 ? void 0 : reading.rpm * engine.rotorAngularSpeed * 60 / (2 * Math.PI);
53
+ engineSignals[`${prefix}failed`] = reading === void 0 ? void 0 : Number(reading.failed);
54
+ engineSignals[`${prefix}thrustN`] = reading?.thrust;
55
+ engineSignals[`${prefix}afterburner`] = reading?.afterburner ?? 0;
56
+ }
47
57
  const telemetry = {
48
58
  airspeed: state.airspeed,
59
+ trueAirspeed: state.airspeed,
60
+ equivalentAirspeed: state.equivalentAirspeed,
61
+ mach: state.mach,
62
+ overspeed: Number(state.overspeed ?? false),
63
+ departure: state.departure ?? 0,
64
+ vortexRing: state.vortexRing ?? 0,
65
+ afterburner: Math.max(0, ...Object.values(state.engines ?? {}).map((engine) => engine.afterburner ?? 0)),
49
66
  altitude,
50
67
  altitudeAGL: state.altitudeAGL,
51
68
  heading: state.yaw,
52
69
  verticalSpeed: state.verticalSpeed,
53
70
  rpm: state.rpm,
71
+ rpmNormalized: state.rpm,
72
+ rotorRpm: spec.engines?.length || spec.engine === void 0 ? void 0 : state.rpm * spec.engine.rotorAngularSpeed * 60 / (2 * Math.PI),
54
73
  pitch: state.pitch,
55
74
  roll: state.roll,
75
+ pitchRate: state.pitchRate,
76
+ rollRate: state.rollRate,
77
+ yawRate: state.yawRate,
78
+ angleOfAttack: state.angleOfAttack,
79
+ sideslip: state.sideslip,
80
+ loadFactor: state.loadFactor,
81
+ groundSpeed: state.velocity === void 0 ? void 0 : Math.hypot(state.velocity[0], state.velocity[2]),
82
+ stalled: Number(state.stalled),
83
+ crashed: Number(state.crashed),
56
84
  power: input.power,
57
85
  pitchInput: input.pitch,
58
86
  rollInput: input.roll,
@@ -60,13 +88,15 @@ function createAircraftVisual(model, spec) {
60
88
  elevator: state.elevator ?? input.pitch,
61
89
  gear,
62
90
  flaps,
91
+ thrustVector: state.thrustVectorPosition ?? 0,
63
92
  engine: Number(input.engine),
64
93
  brake: Number(input.brake),
65
94
  grounded: Number(state.grounded),
95
+ ...engineSignals,
66
96
  ...signals
67
97
  };
68
- interior?.update(telemetry);
69
- animation?.update(telemetry);
98
+ interior?.update(telemetry, timeSeconds);
99
+ animation?.update(telemetry, timeSeconds);
70
100
  },
71
101
  dispose() {
72
102
  const geometries = /* @__PURE__ */ new Set(), materials = /* @__PURE__ */ new Set();
package/dist/audio.d.mts CHANGED
@@ -232,6 +232,8 @@ declare class AudioDirector {
232
232
  private listenerState;
233
233
  private footAcc;
234
234
  private footLast;
235
+ private footGrounded;
236
+ private footAt;
235
237
  private startMs;
236
238
  private lastNow;
237
239
  private frame;
@@ -490,6 +492,8 @@ interface WebAudioBackendOptions {
490
492
  context?: AudioContext;
491
493
  /** Drop a one-shot whose clip is still decoding this many seconds after it was requested. */
492
494
  staleOneShotS?: number;
495
+ /** Retain up to this many decoded PCM bytes; playing/fading clips are never evicted (default 96 MiB). */
496
+ maxDecodedBytes?: number;
493
497
  onError?: (message: string) => void;
494
498
  }
495
499
  /** Plays director commands through Web Audio: buses, panners, looped buffers, fades. */
@@ -499,8 +503,12 @@ declare class WebAudioBackend implements AudioBackend {
499
503
  private readonly staleS;
500
504
  private readonly onError;
501
505
  private readonly master;
506
+ private readonly limiter;
502
507
  private readonly buses;
503
508
  private readonly buffers;
509
+ private readonly bufferSizes;
510
+ private readonly maxDecodedBytes;
511
+ private decodedBytes;
504
512
  private readonly voices;
505
513
  private decoded;
506
514
  private pending;
@@ -516,6 +524,7 @@ declare class WebAudioBackend implements AudioBackend {
516
524
  dispose(): void;
517
525
  private bus;
518
526
  private load;
527
+ private trimBuffers;
519
528
  private start;
520
529
  private set;
521
530
  private stop;
package/dist/audio.mjs CHANGED
@@ -345,6 +345,8 @@ var AudioDirector = class {
345
345
  listenerState;
346
346
  footAcc = 0;
347
347
  footLast;
348
+ footGrounded = false;
349
+ footAt = -Infinity;
348
350
  startMs;
349
351
  lastNow;
350
352
  frame = 0;
@@ -661,8 +663,8 @@ var AudioDirector = class {
661
663
  fadeS: .05
662
664
  });
663
665
  }
664
- const clip = this.pickClip(sound, tick, shot.key);
665
- const pitch = this.basePitch(sound, tick, shot.key) * shot.pitchMul;
666
+ const clip = this.pickClip(sound, tick, shot.key, this.serial);
667
+ const pitch = this.basePitch(sound, tick, shot.key, this.serial) * shot.pitchMul;
666
668
  const voice = `shot:${this.serial++}`;
667
669
  const { entry } = sound;
668
670
  cmds.push({
@@ -1035,16 +1037,23 @@ var AudioDirector = class {
1035
1037
  }
1036
1038
  footsteps(env, ctx, now, tick, cmds) {
1037
1039
  const f = env?.footsteps;
1038
- const travelled = ctx.listener.distance;
1039
- const delta = this.footLast === void 0 ? 0 : travelled - this.footLast;
1040
- this.footLast = travelled;
1040
+ const pos = ctx.listener.position;
1041
+ const delta = this.footLast === void 0 ? 0 : Math.hypot(pos[0] - this.footLast[0], pos[2] - this.footLast[2]);
1042
+ this.footLast = [...pos];
1043
+ const wasGrounded = this.footGrounded;
1044
+ this.footGrounded = !!f && ctx.listener.grounded !== false && evalWhen(f.when, ctx);
1041
1045
  if (!f || ctx.listener.grounded === false || !evalWhen(f.when, ctx)) {
1042
1046
  this.footAcc = 0;
1043
1047
  return;
1044
1048
  }
1049
+ if (!wasGrounded || delta > 4) {
1050
+ this.footAcc = 0;
1051
+ return;
1052
+ }
1045
1053
  const stride = f.strideM ?? .75;
1046
1054
  this.footAcc += delta;
1047
- if (this.footAcc < stride) return;
1055
+ if (this.footAcc < stride || now - this.footAt < 250) return;
1056
+ this.footAt = now;
1048
1057
  this.footAcc -= stride;
1049
1058
  if (this.footAcc > stride) this.footAcc = 0;
1050
1059
  const surface = ctx.listener.surface;
@@ -1053,7 +1062,7 @@ var AudioDirector = class {
1053
1062
  if (!sound) return;
1054
1063
  this.fireOneShot({
1055
1064
  sound,
1056
- gain: (sound.entry.gain ?? 1) * (f.gain ?? 1),
1065
+ gain: (sound.entry.gain ?? 1) * (f.gain ?? 1) * Math.max(.4, Math.min(1.15, ctx.listener.speed / 3)) * (.9 + .1 * unitRandom(this.seed, "step-gain", this.serial)),
1057
1066
  pitchMul: 1,
1058
1067
  bus: sound.entry.bus ?? "sfx",
1059
1068
  key: "footstep"
@@ -1340,8 +1349,12 @@ var WebAudioBackend = class {
1340
1349
  staleS;
1341
1350
  onError;
1342
1351
  master;
1352
+ limiter;
1343
1353
  buses = /* @__PURE__ */ new Map();
1344
1354
  buffers = /* @__PURE__ */ new Map();
1355
+ bufferSizes = /* @__PURE__ */ new Map();
1356
+ maxDecodedBytes;
1357
+ decodedBytes = 0;
1345
1358
  voices = /* @__PURE__ */ new Map();
1346
1359
  decoded = 0;
1347
1360
  pending = 0;
@@ -1350,10 +1363,18 @@ var WebAudioBackend = class {
1350
1363
  constructor(opts) {
1351
1364
  this.provider = opts.provider;
1352
1365
  this.staleS = opts.staleOneShotS ?? .35;
1366
+ this.maxDecodedBytes = Math.max(0, opts.maxDecodedBytes ?? 96 * 1024 * 1024);
1353
1367
  this.onError = opts.onError;
1354
1368
  this.context = opts.context ?? new AudioContext({ latencyHint: "interactive" });
1355
1369
  this.master = this.context.createGain();
1356
- this.master.connect(this.context.destination);
1370
+ this.limiter = this.context.createDynamicsCompressor();
1371
+ this.limiter.threshold.value = -3;
1372
+ this.limiter.knee.value = 3;
1373
+ this.limiter.ratio.value = 12;
1374
+ this.limiter.attack.value = .003;
1375
+ this.limiter.release.value = .2;
1376
+ this.master.connect(this.limiter);
1377
+ this.limiter.connect(this.context.destination);
1357
1378
  for (const bus of AUDIO_BUSES) this.bus(bus);
1358
1379
  }
1359
1380
  get unlocked() {
@@ -1403,6 +1424,10 @@ var WebAudioBackend = class {
1403
1424
  if (this.disposed) return;
1404
1425
  for (const id of [...this.voices.keys()]) this.stop(id, 0);
1405
1426
  this.disposed = true;
1427
+ this.buffers.clear();
1428
+ this.bufferSizes.clear();
1429
+ this.decodedBytes = 0;
1430
+ this.limiter.disconnect();
1406
1431
  this.context.close().catch(() => {});
1407
1432
  }
1408
1433
  bus(name) {
@@ -1417,21 +1442,43 @@ var WebAudioBackend = class {
1417
1442
  }
1418
1443
  load(ref) {
1419
1444
  let p = this.buffers.get(ref);
1445
+ if (p) {
1446
+ this.buffers.delete(ref);
1447
+ this.buffers.set(ref, p);
1448
+ }
1420
1449
  if (!p) {
1421
1450
  this.pending++;
1422
1451
  p = this.provider.load(ref).then((bytes) => this.context.decodeAudioData(bytes.slice(0))).then((buffer) => {
1423
1452
  this.decoded++;
1453
+ if (!this.disposed) {
1454
+ const bytes = buffer.length * buffer.numberOfChannels * 4;
1455
+ this.bufferSizes.set(ref, bytes);
1456
+ this.decodedBytes += bytes;
1457
+ }
1424
1458
  return buffer;
1425
1459
  }).catch((error) => {
1426
1460
  this.onError?.(`audio clip "${ref}" failed to load: ${String(error)}`);
1427
1461
  return null;
1428
1462
  }).finally(() => {
1429
1463
  this.pending--;
1464
+ this.trimBuffers();
1430
1465
  });
1431
1466
  this.buffers.set(ref, p);
1432
1467
  }
1433
1468
  return p;
1434
1469
  }
1470
+ trimBuffers() {
1471
+ if (this.decodedBytes <= this.maxDecodedBytes) return;
1472
+ const playing = new Set([...this.voices.values()].map((v) => v.cmd.ref));
1473
+ for (const ref of this.buffers.keys()) {
1474
+ const bytes = this.bufferSizes.get(ref);
1475
+ if (bytes === void 0 || playing.has(ref)) continue;
1476
+ this.buffers.delete(ref);
1477
+ this.bufferSizes.delete(ref);
1478
+ this.decodedBytes -= bytes;
1479
+ if (this.decodedBytes <= this.maxDecodedBytes) break;
1480
+ }
1481
+ }
1435
1482
  start(cmd) {
1436
1483
  if (!cmd.loop && !this.unlocked) return;
1437
1484
  this.stop(cmd.voice, 0);
@@ -1537,6 +1584,7 @@ var WebAudioBackend = class {
1537
1584
  v.gain.disconnect();
1538
1585
  v.panner?.disconnect();
1539
1586
  } catch {}
1587
+ this.trimBuffers();
1540
1588
  }
1541
1589
  setListener(p, f, u) {
1542
1590
  const l = this.context.listener;
@@ -1,4 +1,4 @@
1
- import { n as CameraPose } from "./renderer-BRtQK4jX.mjs";
1
+ import { n as CameraPose } from "./renderer-CtEtmwJG.mjs";
2
2
 
3
3
  //#region src/camera-track.d.ts
4
4
  interface CameraTrackKeyframe {
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { i as readModelSignals, n as ModelSignals, r as createModelSignalVisual, t as ModelSignalVisual } from "./model-signals-DVlLyP-w.mjs";
1
+ import { a as readModelSignals, n as ModelSignals, r as createModelSignalVisual, t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
2
2
  import { a as createUrlAssetProvider, i as UrlAssetProviderOptions, n as AssetProvider, r as LoadedGltf, t as AssetCache } from "./assets-IbO4GJpF.mjs";
3
- import { A as createWebGlSkyReflectionFilter, C as EarthSkyState, D as SkyReflectionFilter, E as starDirection, F as FrameAdmissionQueue, I as SceneAdmission, M as AdmissionOptions, N as AdmissionSample, O as SkyReflectionState, P as FrameAdmissionOptions, S as CelestialPosition, T as skyTimeMs, _ as SkyFrame, a as RendererBackendPreference, b as SkyVisualOptions, c as TopDownOrtho, d as ShadowFocus, f as ShadowQuality, g as WeatherVisual, h as createGpuFrameTimer, i as RendererBackend, j as reflectionStateFromLights, k as SkyReflections, l as nextWorldOrigin, m as GpuFrameTimerOptions, n as CameraPose, o as RendererOptions, p as GpuFrameTimer, r as Renderer, s as ThreeRenderer, t as AutoWorldOriginOptions, u as orthoFrustum, v as SkyStar, w as evaluateEarthSky, x as defaultSkyPalette, y as SkyVisual } from "./renderer-BRtQK4jX.mjs";
3
+ import { A as createWebGlSkyReflectionFilter, C as EarthSkyState, D as SkyReflectionFilter, E as starDirection, F as FrameAdmissionQueue, I as SceneAdmission, M as AdmissionOptions, N as AdmissionSample, O as SkyReflectionState, P as FrameAdmissionOptions, S as CelestialPosition, T as skyTimeMs, _ as SkyFrame, a as RendererBackendPreference, b as SkyVisualOptions, c as TopDownOrtho, d as ShadowFocus, f as ShadowQuality, g as WeatherVisual, h as createGpuFrameTimer, i as RendererBackend, j as reflectionStateFromLights, k as SkyReflections, l as nextWorldOrigin, m as GpuFrameTimerOptions, n as CameraPose, o as RendererOptions, p as GpuFrameTimer, r as Renderer, s as ThreeRenderer, t as AutoWorldOriginOptions, u as orthoFrustum, v as SkyStar, w as evaluateEarthSky, x as defaultSkyPalette, y as SkyVisual } from "./renderer-CtEtmwJG.mjs";
4
4
  import { a as normalizeInputAxis, i as InputMapOptions, n as InputGamepad, o as resolveAction, r as InputMap, t as InputBindings } from "./input-CD-dHuv0.mjs";
5
5
  import { Command, ControlAction, CustomSkyData, Delta, DiagMessage, EarthObserver, EarthSkyData, EngineEvent, EntityId, JsonObject, JsonValue, Keyframe, MessageLink, ModelSignalSpec, Quat, ResolvedWeather, SceneCamera, SceneInput, SceneManifest, SkyAppearance, SkyBodyData, SkyData, SkyData as SkyData$1, SkyPalette, SkyTime, Vec3, WeatherData, WeatherProfile, resolveWeather, weatherProfile } from "@bendyline/molen-schema";
6
6
  import * as THREE from "three";