@bendyline/molen-client 0.0.9 → 0.0.11

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/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-Dzus24ZF.mjs";
2
2
 
3
3
  //#region src/camera-track.d.ts
4
4
  interface CameraTrackKeyframe {
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
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";
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
- 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";
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-Dzus24ZF.mjs";
4
+ import { a as normalizeInputAxis, i as InputMapOptions, n as InputGamepad, o as resolveAction, r as InputMap, t as InputBindings } from "./input-Ckev_Kvj.mjs";
5
+ import { Command, ControlAction, CustomSkyData, Delta, DiagMessage, EarthObserver, EarthSkyData, EngineEvent, EntityId, JsonObject, JsonValue, Keyframe, LiveryData, LiveryGraphic, 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";
7
7
  import { Intersection, Object3D } from "three";
8
8
  import { BakedMaterial, BakedMaterialStore, MaterialBaker } from "@bendyline/molen-materials";
@@ -31,8 +31,9 @@ interface AdaptiveQualitySample {
31
31
  /** False while hidden, suspended, or deliberately not rendering. Resets measurement history. */
32
32
  active?: boolean;
33
33
  /**
34
- * Loading never authorizes an upgrade. With CPU/GPU work measurements it lowers detail only
35
- * when that work itself is heavy; otherwise sustained overload while loading still lowers it.
34
+ * Loading alone never authorizes an upgrade. Sustained on-target frames with both CPU and GPU
35
+ * headroom can recover during continuous streaming. Measured loading stalls do not lower detail
36
+ * unless rendering itself is heavy.
36
37
  */
37
38
  loading?: boolean;
38
39
  /** Optional measured work, excluding waiting for the next animation frame. */
@@ -225,6 +226,7 @@ interface SceneBackend {
225
226
  destroy(id: EntityId): void;
226
227
  setTransform(id: EntityId, transform: InterpTransform): void;
227
228
  setModelSignals?(id: EntityId, spec: ModelSignalSpec | undefined, signals: ModelSignals): void;
229
+ setLivery?(id: EntityId, data: LiveryData | undefined): void;
228
230
  /** Optional light surface (per-entity `light` components). */
229
231
  createLight?(id: EntityId, light: LightData): void;
230
232
  updateLight?(id: EntityId, light: LightData): void;
@@ -505,6 +507,7 @@ declare class ThreeSceneBackend implements SceneBackend {
505
507
  private animationTickRate;
506
508
  private readonly objects;
507
509
  private readonly gltf;
510
+ private readonly liveries;
508
511
  private readonly modelSignals;
509
512
  private readonly identities;
510
513
  private readonly lights;
@@ -553,6 +556,9 @@ declare class ThreeSceneBackend implements SceneBackend {
553
556
  private applyAnimation;
554
557
  updateRenderable(id: EntityId, renderable: Renderable): void;
555
558
  /** Latest mirrored values are retained while the model loads. No simulation state is changed. */
559
+ setLivery(id: EntityId, data: LiveryData | undefined): void;
560
+ private bindLivery;
561
+ /** Latest mirrored values are retained while the model loads. No simulation state is changed. */
556
562
  setModelSignals(id: EntityId, spec: ModelSignalSpec | undefined, signals: ModelSignals): void;
557
563
  private bindModelSignals;
558
564
  private applyModelSignals;
@@ -751,6 +757,17 @@ interface MountedExperience {
751
757
  */
752
758
  declare function mountExperience(opts: MountExperienceOptions): Promise<MountedExperience>;
753
759
  //#endregion
760
+ //#region src/livery.d.ts
761
+ interface LiveryVisual {
762
+ readonly warnings: readonly string[];
763
+ /** Restore originals and release only the resources owned by this livery. */
764
+ dispose(): void;
765
+ }
766
+ /** Flat vector artwork, including outlined text; no browser fonts or image downloads. */
767
+ declare function liveryGraphicTexture(graphic: LiveryGraphic, size?: number): THREE.DataTexture;
768
+ /** Apply to an instance, never a cache template. Does not mutate shared materials or geometry. */
769
+ declare function applyLivery(model: THREE.Object3D, data: LiveryData): LiveryVisual;
770
+ //#endregion
754
771
  //#region src/material-store.d.ts
755
772
  /**
756
773
  * Baked materials kept in IndexedDB across visits; pair with `withBakedMaterialStore` from
@@ -853,4 +870,4 @@ declare const defaultEnvironment: EnvironmentData;
853
870
  */
854
871
  declare function applyEnvironment(renderer: Renderer, env: EnvironmentData): void;
855
872
  //#endregion
856
- export { type AdaptiveQualityChange, AdaptiveQualityController, type AdaptiveQualityOptions, type AdaptiveQualityReason, type AdaptiveQualitySample, type AdaptiveQualityStats, type AdmissionOptions, type AdmissionSample, AssetCache, type AssetOptions, type AssetProvider, type AutoWorldOriginOptions, type CameraPose, type CameraTarget, type CelestialPosition, type ClientCore, type ClientCoreOptions, type ClientDiagCode, type ClientError, type ClientOptions, type CustomSkyData, type DecoderConfig, type EarthObserver, type EarthSkyData, type EarthSkyState, type EnvironmentData, type FrameAdmissionOptions, FrameAdmissionQueue, type GpuFrameTimer, type GpuFrameTimerOptions, type InputBindings, type InputGamepad, InputMap, type InputMapOptions, type InputRuleOptions, type InterpTransform, InterpolationBuffer, type KindContext, type KindHandle, type KindView, type LightData, type LoadedGltf, MaterialResolver, type MirrorReader, type ModelSignalVisual, type ModelSignals, type MolenClient, type MountExperienceOptions, type MountedExperience, type Renderable, type RenderableKind, Renderer, type RendererBackend, type RendererBackendPreference, type RendererOptions, type ResolvedWeather, type SceneAdmission, type SceneBackend, SceneMirror, type SceneOptimizationOptions, type ShadowFocus, type ShadowQuality, type SkyAppearance, type SkyBodyData, type SkyData, type SkyFrame, type SkyPalette, type SkyReflectionFilter, type SkyReflectionState, SkyReflections, type SkyStar, type SkyTime, SkyVisual, type SkyVisualOptions, type StarCatalogRow, type StaticBatchOptions, THREE, type ThreeRenderer, ThreeSceneBackend, type TopDownOrtho, type Unsubscribe, type UrlAssetProviderOptions, type WeatherData, type WeatherProfile, WeatherVisual, applyEnvironment, applyInputRules, applySceneCamera, computeClipTime, createClient, createClientCore, createGltfLoader, createGpuFrameTimer, createIndexedDbMaterialStore, createModelSignalVisual, createSnapshotViewer, createUrlAssetProvider, createViewer, createWebGlSkyReflectionFilter, decodeStarCatalog, decodeStarCatalogRows, defaultEnvironment, defaultSkyPalette, encodeStarCatalog, evaluateEarthSky, followCameraPose, lerp3, localCommand, materialFromBaked, mountExperience, nextWorldOrigin, nlerp4, normalizeInputAxis, orthoFrustum, readModelSignals, reflectionStateFromLights, resolveAction, resolveWeather, skyTimeMs, starDirection, weatherProfile };
873
+ export { type AdaptiveQualityChange, AdaptiveQualityController, type AdaptiveQualityOptions, type AdaptiveQualityReason, type AdaptiveQualitySample, type AdaptiveQualityStats, type AdmissionOptions, type AdmissionSample, AssetCache, type AssetOptions, type AssetProvider, type AutoWorldOriginOptions, type CameraPose, type CameraTarget, type CelestialPosition, type ClientCore, type ClientCoreOptions, type ClientDiagCode, type ClientError, type ClientOptions, type CustomSkyData, type DecoderConfig, type EarthObserver, type EarthSkyData, type EarthSkyState, type EnvironmentData, type FrameAdmissionOptions, FrameAdmissionQueue, type GpuFrameTimer, type GpuFrameTimerOptions, type InputBindings, type InputGamepad, InputMap, type InputMapOptions, type InputRuleOptions, type InterpTransform, InterpolationBuffer, type KindContext, type KindHandle, type KindView, type LightData, type LiveryVisual, type LoadedGltf, MaterialResolver, type MirrorReader, type ModelSignalVisual, type ModelSignals, type MolenClient, type MountExperienceOptions, type MountedExperience, type Renderable, type RenderableKind, Renderer, type RendererBackend, type RendererBackendPreference, type RendererOptions, type ResolvedWeather, type SceneAdmission, type SceneBackend, SceneMirror, type SceneOptimizationOptions, type ShadowFocus, type ShadowQuality, type SkyAppearance, type SkyBodyData, type SkyData, type SkyFrame, type SkyPalette, type SkyReflectionFilter, type SkyReflectionState, SkyReflections, type SkyStar, type SkyTime, SkyVisual, type SkyVisualOptions, type StarCatalogRow, type StaticBatchOptions, THREE, type ThreeRenderer, ThreeSceneBackend, type TopDownOrtho, type Unsubscribe, type UrlAssetProviderOptions, type WeatherData, type WeatherProfile, WeatherVisual, applyEnvironment, applyInputRules, applyLivery, applySceneCamera, computeClipTime, createClient, createClientCore, createGltfLoader, createGpuFrameTimer, createIndexedDbMaterialStore, createModelSignalVisual, createSnapshotViewer, createUrlAssetProvider, createViewer, createWebGlSkyReflectionFilter, decodeStarCatalog, decodeStarCatalogRows, defaultEnvironment, defaultSkyPalette, encodeStarCatalog, evaluateEarthSky, followCameraPose, lerp3, liveryGraphicTexture, localCommand, materialFromBaked, mountExperience, nextWorldOrigin, nlerp4, normalizeInputAxis, orthoFrustum, readModelSignals, reflectionStateFromLights, resolveAction, resolveWeather, skyTimeMs, starDirection, weatherProfile };