@adatechnology/game-vehicles-three 0.5.0 → 0.6.0

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/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
- export { B as BuildVehicleOptions, a as BuiltVehicle, D as DEFAULT_TEST_VEHICLES, b as DEFAULT_TEST_WRECKS, c as DocumentLike, E as EffectsLike, F as FleetDims, M as ModuleRoomLike, P as PAGE_ITEM_ALIASES, d as PAGE_SCENARIO_ALIASES, V as VEHICLES_AREA_ID, e as VEHICLE_SCENARIO_IDS, f as VehicleEffectIds, g as VehicleFleetContent, h as VehicleQuality, i as VehicleSoundIds, j as VehicleWreck, k as VehiclesContext, l as VehiclesRoom, m as VehiclesTestFleet, n as VehiclesTestOptions, o as VehiclesThree, p as VehiclesThreeOptions, q as createVehiclesTestModule, r as createVehiclesThree, s as defaultEffectIds, t as defaultSoundIds, u as loadVehiclesTestModule } from './testing-DmGv7Gpb.js';
2
- import { EffectSink } from '@adatechnology/game-contracts';
1
+ import { E as EngineProfile, V as VehicleSoundKeys } from './testing-gEnSqEF6.js';
2
+ export { B as BIKE_ENGINE, a as BuildVehicleOptions, b as BuiltVehicle, C as CAR_ENGINE, c as CRASH_SPEEDS, D as DEFAULT_TEST_VEHICLES, d as DEFAULT_TEST_WRECKS, e as DEFAULT_VEHICLE_SOUND_KEYS, f as DocumentLike, g as ENGINE_PROFILES, h as EffectsLike, i as EngineLayer, j as EngineLoadLayer, F as FleetDims, M as ModuleRoomLike, P as PAGE_ITEM_ALIASES, k as PAGE_SCENARIO_ALIASES, l as PROVING_AREA_ID, m as PROVING_TEXT, n as ProvingModuleOptions, o as ProvingRoomLike, p as ProvingText, T as TRUCK_ENGINE, q as VEHICLES_AREA_ID, r as VEHICLE_SCENARIO_IDS, s as VehicleEffectIds, t as VehicleFleetContent, u as VehicleQuality, v as VehicleSoundIds, w as VehicleWreck, x as VehiclesContext, y as VehiclesRoom, z as VehiclesTestFleet, A as VehiclesTestOptions, G as VehiclesThree, H as VehiclesThreeOptions, I as createProvingModule, J as createVehiclesTestModule, K as createVehiclesThree, L as defaultEffectIds, N as defaultSoundIds, O as loadProvingModule, Q as loadVehiclesTestModule } from './testing-gEnSqEF6.js';
3
+ import { EffectSink, Vec3, AudioSink } from '@adatechnology/game-contracts';
3
4
  import { CabinSource } from '@adatechnology/game-vehicles';
5
+ import { LoopRecipe, Falloff, SoundRecipe, SoundBank } from '@adatechnology/game-audio';
6
+ import '@adatechnology/game-vehicles-proving';
4
7
 
5
8
  /**
6
9
  * Keeps the host's effects told where the cabins of the vehicles are and how open they are (`EffectSink.enclose`), so the smoke, dust and steam
@@ -23,6 +26,92 @@ interface CabinSmoke {
23
26
  }
24
27
  declare function createCabinSmoke(): CabinSmoke;
25
28
 
29
+ /** How a vehicle loop falls off: `1 / (1 + d² × 0.004)`, the game's one-shot curve, with the cutoff muffled by `1 + d × 0.01` (a car far away is dull). */
30
+ declare const VEHICLE_LOOP_FALLOFF: Falloff;
31
+ /** The engines (car, truck, bike) and the tyres, as loops. */
32
+ declare const VEHICLE_LOOPS: readonly LoopRecipe[];
33
+ /** The one-shots: the starter, the engine stopping, crashes by speed, and the doors, trunk and hood of a car. */
34
+ declare const VEHICLE_SOUNDS: readonly SoundRecipe[];
35
+ declare const VEHICLE_SOUND_BANK: SoundBank;
36
+
37
+ /** What one engine loop is set to this frame. `frequency` is absent for the load layer (noise has no pitch). */
38
+ type EngineLayerSetting = {
39
+ readonly sound: string;
40
+ readonly volume: number;
41
+ readonly frequency?: number;
42
+ readonly cutoff: number;
43
+ };
44
+ type EngineMixInput = {
45
+ readonly rpm: number;
46
+ /** 0..1, how open the throttle is (the engine's load). */
47
+ readonly throttle: number;
48
+ };
49
+ /** The firing frequency of a four-stroke engine, Hz: every cylinder fires once every two turns. */
50
+ declare const firingHz: (profile: EngineProfile, rpm: number) => number;
51
+ /** RPM as a share of the range: 0 at idle, 1 at the redline. */
52
+ declare const rpmShare: (profile: EngineProfile, rpm: number) => number;
53
+ /** Equal-power weight of a layer centred at `centre` with `width` at the normalised RPM `n`. */
54
+ declare const layerWeight: (centre: number, width: number, n: number) => number;
55
+ /**
56
+ * The engine's loops for an RPM and a throttle: every tone layer at the firing frequency times its harmonic, faded in and out across the RPM range so
57
+ * the sum stays even, louder and brighter under load; the load layer opens with the throttle. A stopped engine (`rpm` 0) is silent.
58
+ */
59
+ declare function engineMix(profile: EngineProfile, input: EngineMixInput): EngineLayerSetting[];
60
+ /**
61
+ * A guess of the RPM from the speed for a driver without an engine model: the gear is kept between calls (up above 85% of the redline, down below
62
+ * 40%), so the RPM climbs and drops at each shift as it does in a real car.
63
+ */
64
+ declare function createGearGuess(profile: EngineProfile): {
65
+ rpm(speed: number, throttle: number): number;
66
+ readonly gear: number;
67
+ };
68
+
69
+ /** What the vehicle is doing this frame. Without `rpm` (a driver with no engine model) the RPM is guessed from the speed through the profile's gears. */
70
+ type VehicleSoundFrame = {
71
+ readonly dt: number;
72
+ readonly position: Vec3;
73
+ /** m/s, signed or not. */
74
+ readonly speed: number;
75
+ /** 0..1. */
76
+ readonly throttle: number;
77
+ readonly rpm?: number;
78
+ /** 0..1: how much the tyres slide (the largest wheel slip; 1 = locked or spinning). */
79
+ readonly slip?: number;
80
+ /** What the tyres are on: `dirt` for earth, gravel, sand or grass; anything else squeals as asphalt. */
81
+ readonly surface?: 'asphalt' | 'dirt';
82
+ };
83
+ type VehicleSoundOptions = {
84
+ readonly profile?: EngineProfile;
85
+ /** Any of the one-shot and tyre ids, pointed at other sounds. */
86
+ readonly sounds?: Partial<VehicleSoundKeys>;
87
+ /** Seconds the starter turns before the engine catches (the `engine_start` recipe catches at 0.75 s). */
88
+ readonly crankSeconds?: number;
89
+ };
90
+ /** What was asked of the sink, for the checks and the bench: the RPM in use and the level of each loop. */
91
+ type VehicleSoundReading = {
92
+ readonly running: boolean;
93
+ readonly rpm: number;
94
+ readonly levels: Readonly<Record<string, number>>;
95
+ };
96
+ type VehicleSound = {
97
+ /** Turns the key: the starter, then the engine catches with a flare of RPM. `fail` cranks without catching (no fuel, a dead engine). */
98
+ start(position: Vec3, options?: {
99
+ readonly fail?: boolean;
100
+ }): void;
101
+ /** Ignition off: the engine runs down. */
102
+ stop(position: Vec3): void;
103
+ /** A hit at `speed` m/s: light, medium or heavy by speed, louder with it. */
104
+ crash(speed: number, position: Vec3): 'light' | 'medium' | 'heavy';
105
+ update(frame: VehicleSoundFrame): void;
106
+ readonly reading: VehicleSoundReading;
107
+ dispose(): void;
108
+ };
109
+ /**
110
+ * The sounds of one vehicle on a host's sink (`ModuleHost.audio`): the engine loops by RPM and load, the starter, the tyres skidding and rolling,
111
+ * and crashes by speed. The loops are placed at the vehicle every frame (distance and side come from the sink). Works without a sink (silent).
112
+ */
113
+ declare function createVehicleSound(audio: AudioSink | undefined, options?: VehicleSoundOptions): VehicleSound;
114
+
26
115
  /**
27
116
  * The light mode of the team's Frota Leve (frota-leve.js 14202-14310): a built vehicle fused into six meshes, one per class of material,
28
117
  * with the meshes nobody sees from outside left out. A literal port: the classes, the thresholds (3 cm prune, 0.99 opacity, 0.5 metalness,
@@ -64,6 +153,10 @@ declare function liteMeshes(THREE: any, fusion: LiteFusion, materials: Record<Li
64
153
 
65
154
  /** Past this distance (m) an untouched vehicle draws fused: nobody sees a door seam from here, and the full model costs hundreds of draw calls. */
66
155
  declare const VEHICLE_LOD_DISTANCE = 14;
156
+ type VehicleLodOptions = {
157
+ /** The clock (ms) the quiet time is read from (default `performance.now`). */
158
+ readonly now?: () => number;
159
+ };
67
160
  type VehicleLod = {
68
161
  /** `touched`: hit or driven, from now on it always draws in full (its damage only exists there); `posed`: a door, hood or lid is open now (fused only while all are shut). */
69
162
  update(distance: number, touched: boolean, posed?: boolean): void;
@@ -71,6 +164,6 @@ type VehicleLod = {
71
164
  dispose(): void;
72
165
  };
73
166
  /** Shows `full` near and the kit's fused light mode (one mesh per class of material) far, in `root`'s own space. Hit tests read the full model, visible or not. */
74
- declare function createVehicleLod(kit: any, context: any, root: any, full: any): VehicleLod;
167
+ declare function createVehicleLod(kit: any, context: any, root: any, full: any, options?: VehicleLodOptions): VehicleLod;
75
168
 
76
- export { type CabinSmoke, LITE_CLASSES, type LiteClass, type LiteFusion, PRUNE_BELOW, VEHICLE_LOD_DISTANCE, type VehicleLod, classColor, classify, createCabinSmoke, createVehicleLod, fuse, liteMaterials, liteMeshes };
169
+ export { type CabinSmoke, type EngineLayerSetting, type EngineMixInput, EngineProfile, LITE_CLASSES, type LiteClass, type LiteFusion, PRUNE_BELOW, VEHICLE_LOD_DISTANCE, VEHICLE_LOOPS, VEHICLE_LOOP_FALLOFF, VEHICLE_SOUNDS, VEHICLE_SOUND_BANK, type VehicleLod, type VehicleSound, type VehicleSoundFrame, VehicleSoundKeys, type VehicleSoundOptions, type VehicleSoundReading, classColor, classify, createCabinSmoke, createGearGuess, createVehicleLod, createVehicleSound, engineMix, firingHz, fuse, layerWeight, liteMaterials, liteMeshes, rpmShare };