@adatechnology/game-vehicles-three 0.8.6 → 0.9.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.
@@ -1009,6 +1009,8 @@ var DEFAULT_VEHICLE_SOUND_KEYS = {
1009
1009
  skidAsphalt: "tire_skid_asphalt",
1010
1010
  skidDirt: "tire_skid_dirt",
1011
1011
  roll: "tire_roll",
1012
+ rollDirt: "tire_roll_gravel",
1013
+ airBrake: "air_brake",
1012
1014
  brakeSqueal: "brake_squeal",
1013
1015
  hitBody: "vehicle_hit_pedestrian",
1014
1016
  siren: "siren",
@@ -1052,6 +1054,9 @@ var BIKE_ENGINE = {
1052
1054
  closedThrottle: 0.5
1053
1055
  };
1054
1056
  var ENGINE_PROFILES = { car: CAR_ENGINE, truck: TRUCK_ENGINE, bike: BIKE_ENGINE };
1057
+ var TRUCK_GROUPS = /* @__PURE__ */ new Set(["heavy", "agricultural"]);
1058
+ var engineProfileOfGroup = (group) => group === "motorcycles" ? BIKE_ENGINE : TRUCK_GROUPS.has(group) ? TRUCK_ENGINE : CAR_ENGINE;
1059
+ var hornOfGroup = (group) => group === "motorcycles" ? "horn_bike" : TRUCK_GROUPS.has(group) ? "horn_truck" : "horn_car";
1055
1060
 
1056
1061
  // src/test-area/types.ts
1057
1062
  var defaultEffectIds = {
@@ -1124,12 +1129,13 @@ function createVehicleSound(audio, options = {}) {
1124
1129
  const profile = options.profile ?? CAR_ENGINE;
1125
1130
  const keys = { ...DEFAULT_VEHICLE_SOUND_KEYS, ...options.sounds };
1126
1131
  const crankSeconds = options.crankSeconds ?? 0.75;
1132
+ const airBrake = options.airBrake ?? profile.id === TRUCK_ENGINE.id;
1127
1133
  const gears = createGearGuess(profile);
1128
1134
  const loops = /* @__PURE__ */ new Map();
1129
1135
  const budget = options.budget;
1130
1136
  const self = {};
1131
1137
  const levels = {};
1132
- const state = { running: false, cranking: 0, catches: false, flare: 0, rpm: 0, sirenPhase: 0 };
1138
+ const state = { running: false, cranking: 0, catches: false, flare: 0, rpm: 0, sirenPhase: 0, rolling: false };
1133
1139
  const loopOf = (sound) => {
1134
1140
  let handle = loops.get(sound);
1135
1141
  if (!handle && audio?.loop) {
@@ -1190,7 +1196,15 @@ function createVehicleSound(audio, options = {}) {
1190
1196
  const dirt = frame.surface === "dirt";
1191
1197
  setLoop(keys.skidAsphalt, heard * (dirt ? 0 : 0.16 * slide), frame.position, { cutoff: 1700 + 600 * slide });
1192
1198
  setLoop(keys.skidDirt, heard * (dirt ? 0.2 * slide : 0), frame.position, { cutoff: 500 + 500 * slide });
1193
- setLoop(keys.roll, heard * 0.06 * clamp012(speed / 25), frame.position, { cutoff: 250 + 45 * Math.min(speed, 40) });
1199
+ setLoop(keys.roll, heard * (dirt ? 0 : 0.06 * clamp012(speed / 25)), frame.position, { cutoff: 250 + 45 * Math.min(speed, 40) });
1200
+ setLoop(keys.rollDirt, heard * (dirt ? 0.1 * clamp012(speed / 20) : 0), frame.position, { cutoff: 700 + 60 * Math.min(speed, 30) });
1201
+ if (airBrake) {
1202
+ if (speed > 2) state.rolling = true;
1203
+ else if (state.rolling && speed < 0.8) {
1204
+ state.rolling = false;
1205
+ if ((frame.brake ?? 0) > 0.3 && heard > 0) play(keys.airBrake, frame.position, 0.8);
1206
+ }
1207
+ }
1194
1208
  const squeal = clamp012(((frame.brake ?? 0) - 0.3) / 0.4) * clamp012(speed / 0.8) * clamp012((5 - speed) / 2) * (slide > 0 ? 0 : 1);
1195
1209
  setLoop(keys.brakeSqueal, heard * 0.05 * squeal, frame.position, { cutoff: 3200 + 400 * squeal });
1196
1210
  const siren = frame.siren ?? "off";
@@ -1254,6 +1268,7 @@ var VEHICLE_LOOPS = [
1254
1268
  noiseLoop("tire_skid_asphalt", "bandpass", 1900, 5, "rubber squealing on asphalt: a narrow band of noise near 2 kHz"),
1255
1269
  noiseLoop("tire_skid_dirt", "lowpass", 700, 0.8, "tyres sliding on dirt and gravel: a dull, wide hiss"),
1256
1270
  noiseLoop("tire_roll", "lowpass", 400, 0.7, "road noise of the tyres rolling, brighter with the speed"),
1271
+ noiseLoop("tire_roll_gravel", "bandpass", 1400, 0.6, "tyres rolling on gravel: a wide crunching hiss, louder with the speed"),
1257
1272
  // a pad on a disc: a thin, nearly pure whistle near 3.4 kHz (a narrow band of noise, so it wavers as a real squeal does)
1258
1273
  // a siren: a square through a low-pass, its pitch swept by the vehicle every frame (wail: a slow rise and fall; yelp: a fast one)
1259
1274
  toneLoop("siren", "square", "lowpass", 2600, 0.8, "emergency siren, the sweep driven by the vehicle"),
@@ -1320,10 +1335,14 @@ var VEHICLE_SOUNDS = [
1320
1335
  // the game's horn (two squares at 415 and 523 Hz, jogo L70272) heard from where the car is; a truck's air horn lower and longer
1321
1336
  recipe("horn_car", [tone({ wave: "square", f: 415, d: 0.6, vol: 0.09 }), tone({ wave: "square", f: 523, d: 0.6, vol: 0.09 })], "car horn: the game chord, placed and panned"),
1322
1337
  recipe("horn_truck", [tone({ wave: "sawtooth", f: 220, d: 1.1, vol: 0.1 }), tone({ wave: "sawtooth", f: 277, d: 1.1, vol: 0.08 }), noise({ type: "bandpass", f: 900, q: 2, d: 1.1, vol: 0.05 })], "truck air horn: low reedy chord"),
1338
+ recipe("horn_bike", [tone({ wave: "square", f: 620, d: 0.35, vol: 0.07 }), tone({ wave: "square", f: 780, d: 0.35, vol: 0.07 })], "motorcycle horn: a short, thin two-note beep"),
1339
+ // the compressed air let out of a truck's brake chambers as it stops: a hiss that dies away
1340
+ recipe("air_brake", [noise({ type: "highpass", f: 2200, a: 0.01, d: 1.1, vol: 0.28 }), noise({ type: "bandpass", f: 900, q: 0.8, d: 0.35, vol: 0.2 }), tone({ f: 120, f2: 70, d: 0.12, vol: 0.2 })], "air brakes: the chambers venting as the truck stops"),
1323
1341
  // a car door is a padded "tum" with a latch, not a hollow metal box (the fridge's shut_metal)
1324
1342
  recipe("car_door_open", [...latch(0, 0.32), noise({ f: 400, d: 0.06, vol: 0.14, delay: 0.035 })], "car door: the handle pulled, the latch released, the seal letting go"),
1325
1343
  recipe("car_door_close", [tone({ f: 75, f2: 48, d: 0.16, vol: 0.75 }), noise({ f: 320, d: 0.1, vol: 0.6 }), ...latch(0.012, 0.3)], "car door shut: a dull padded thump and the latch catching"),
1326
1344
  recipe("car_trunk_close", [tone({ f: 90, f2: 55, d: 0.15, vol: 0.65 }), noise({ type: "bandpass", f: 500, q: 1, d: 0.12, vol: 0.5 }), ...latch(0.01, 0.28), noise({ type: "bandpass", f: 1800, q: 3, d: 0.04, vol: 0.1, delay: 0.06 })], "trunk or hatch shut: a lighter thump, the latch and a small rattle"),
1345
+ recipe("car_hood_open", [...latch(0, 0.3), tone({ f: [180, 230], f2: 140, d: 0.3, vol: 0.04, delay: 0.06 }), noise({ type: "bandpass", f: 700, q: 2, d: 0.25, vol: 0.12, delay: 0.05 })], "hood released: the latch giving and the lid rising a little on its springs"),
1327
1346
  recipe("car_hood_close", [tone({ f: 70, f2: 40, d: 0.22, vol: 0.8 }), noise({ type: "bandpass", f: 850, q: 1.4, d: 0.2, vol: 0.6, wet: 0.3 }), tone({ f: 900, f2: 860, d: 0.18, vol: 0.05 }), ...latch(0.015, 0.3)], "hood slammed: a big sheet of metal ringing a little, the latch")
1328
1347
  ];
1329
1348
  var CAR_RECORDED_RPM = { idle: 1e3, high: 2520 };
@@ -1335,6 +1354,13 @@ var CAR_START_RUN_STOP = {
1335
1354
  /** The ignition off: the engine running down to the end of the file. */
1336
1355
  stop: { offset: 9.96, duration: 0.64 }
1337
1356
  };
1357
+ var idleLayer = (id, file, rpm, profile) => ({
1358
+ id,
1359
+ file,
1360
+ loop: true,
1361
+ baseFrequency: firingHz(profile, rpm),
1362
+ falloff: VEHICLE_LOOP_FALLOFF
1363
+ });
1338
1364
  var carLayer = (id, file, rpm, harmonic, offset) => ({
1339
1365
  id,
1340
1366
  file,
@@ -1353,9 +1379,20 @@ var VEHICLE_SAMPLE_ALIASES = [
1353
1379
  { id: "engine_start", file: "engine_start_run_stop", only: CAR_START_RUN_STOP.take, ...CAR_START_RUN_STOP.start, falloff: VEHICLE_LOOP_FALLOFF },
1354
1380
  { id: "engine_stop", file: "engine_start_run_stop", only: CAR_START_RUN_STOP.take, ...CAR_START_RUN_STOP.stop, falloff: VEHICLE_LOOP_FALLOFF },
1355
1381
  { id: "car_door_close", file: "car_door_shut" },
1356
- { id: "car_trunk_close", file: "car_trunk_shut" }
1382
+ { id: "car_trunk_close", file: "car_trunk_shut" },
1383
+ { id: "car_hood_close", file: "car_hood_shut" },
1384
+ // a crash by speed: a dent in the plastic, the body folding, the wreck (file ids that are not the recipes' own: `crash_light` and its kin would read as tiers of `crash`)
1385
+ { id: "crash_light", file: "crash_dent" },
1386
+ { id: "crash_medium", file: "crash_fold" },
1387
+ { id: "crash_heavy", file: "crash_wreck" },
1388
+ // tyres: the squeal of rubber on asphalt and the crunch of gravel, chained like the engines
1389
+ { id: "tire_skid_asphalt", file: "tire_skid_asphalt_loop", loop: { crossfade: 0.6 }, falloff: VEHICLE_LOOP_FALLOFF },
1390
+ { id: "tire_roll_gravel", file: "tire_roll_gravel_loop", loop: { crossfade: 0.6 }, falloff: VEHICLE_LOOP_FALLOFF },
1391
+ // the idle of a truck and of a motorcycle, at the profile's idle RPM (the take plays at its own pitch there); the other layers stay on their recipes
1392
+ idleLayer("engine_truck_low", "engine_loop_truck_idle", TRUCK_ENGINE.idleRpm, TRUCK_ENGINE),
1393
+ idleLayer("engine_bike_low", "engine_loop_bike_idle", BIKE_ENGINE.idleRpm, BIKE_ENGINE)
1357
1394
  ];
1358
- var VEHICLE_PRELOAD_SOUNDS = [...VEHICLE_SAMPLE_ALIASES.map((alias) => alias.id), "car_door_open"];
1395
+ var VEHICLE_PRELOAD_SOUNDS = [...VEHICLE_SAMPLE_ALIASES.map((alias) => alias.id), "car_door_open", "car_hood_open", "horn_car", "horn_truck", "horn_bike", "air_brake"];
1359
1396
  var VEHICLE_SOUND_BANK = { id: "vehicles_three", sounds: VEHICLE_SOUNDS, loops: VEHICLE_LOOPS, sampleAliases: VEHICLE_SAMPLE_ALIASES };
1360
1397
 
1361
1398
  // src/test-area/module.ts
@@ -3379,7 +3416,7 @@ function createProvingModule(options) {
3379
3416
  if (id === "turn_circle") run.driver.place(0, TRACK.start, 0);
3380
3417
  rig.vehicle?.reset();
3381
3418
  stopEngine();
3382
- engine = createVehicleSound(host.audio, { sounds });
3419
+ engine = createVehicleSound(host.audio, { sounds, profile: engineProfileOfGroup(car.subject.category) });
3383
3420
  engine.start([car.built.group.position.x, 0.5, car.built.group.position.z]);
3384
3421
  host.log(fillText(text.log.start, name(settings.vehicle), text.tests[id] ?? id));
3385
3422
  drawBoard();
@@ -3436,7 +3473,7 @@ function createProvingModule(options) {
3436
3473
  gauge: kitFor(three).materials?.gauge,
3437
3474
  needle: kitFor(three).materials?.amber,
3438
3475
  // the engine's own sound turns the key (starter, catch, idle by RPM)
3439
- sounds: { starter: "" },
3476
+ sounds: { starter: "", horn: hornOfGroup(car.subject.category) },
3440
3477
  hasKey,
3441
3478
  weather,
3442
3479
  stock: (compartment) => options.stock?.(compartment, settings.vehicle) ?? [],
@@ -3476,7 +3513,7 @@ function createProvingModule(options) {
3476
3513
  }
3477
3514
  rig.vehicle?.reset();
3478
3515
  stopEngine();
3479
- engine = createVehicleSound(host.audio, { sounds });
3516
+ engine = createVehicleSound(host.audio, { sounds, profile: engineProfileOfGroup(car.subject.category) });
3480
3517
  host.bench?.sheet?.({ kicker: text.name, title: fillText(text.log.drive, name(settings.vehicle)), body: `${text.cabin.keys} \xB7 ${sysText.keys} \xB7 ${sysText.bodyKeys}` });
3481
3518
  host.log(fillText(text.log.drive, name(settings.vehicle)));
3482
3519
  };
@@ -3881,6 +3918,7 @@ function createProvingModule(options) {
3881
3918
  lent.audio?.register?.(CABIN_BANK);
3882
3919
  lent.audio?.register?.(VEHICLE_SOUND_BANK);
3883
3920
  lent.audio?.register?.(RADIO_BANK);
3921
+ lent.audio?.preload?.(VEHICLE_PRELOAD_SOUNDS);
3884
3922
  const stopChange = lent.bench?.onChange(onChange);
3885
3923
  const stopFrame = lent.onFrame(frame);
3886
3924
  const stopClear = lent.onClear?.(() => {
@@ -3924,6 +3962,8 @@ export {
3924
3962
  TRUCK_ENGINE,
3925
3963
  BIKE_ENGINE,
3926
3964
  ENGINE_PROFILES,
3965
+ engineProfileOfGroup,
3966
+ hornOfGroup,
3927
3967
  VEHICLE_LOOP_FALLOFF,
3928
3968
  VEHICLE_LOOPS,
3929
3969
  VEHICLE_SOUNDS,
@@ -3960,4 +4000,4 @@ export {
3960
4000
  createProvingModule,
3961
4001
  loadProvingModule
3962
4002
  };
3963
- //# sourceMappingURL=chunk-VF34TPYO.js.map
4003
+ //# sourceMappingURL=chunk-NVMORI7X.js.map