@adatechnology/game-vehicles-three 0.8.3 → 0.8.4

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
@@ -173,6 +173,12 @@ type VehicleSound = {
173
173
  readonly reading: VehicleSoundReading;
174
174
  dispose(): void;
175
175
  };
176
+ /**
177
+ * A tyre's slide for `VehicleSoundFrame.slip`, from how much of its grip it uses (the semi driver's `state.slip`: force over what the tyre
178
+ * holds, 1 = saturated). A tyre pulling hard but still holding is silent; it squeals only near the limit and slides fully once saturated,
179
+ * so full throttle that the tyre carries is no skid, and wheelspin or a locked wheel is.
180
+ */
181
+ declare const slideOfGrip: (usage: number) => number;
176
182
  /**
177
183
  * 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,
178
184
  * 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).
@@ -584,4 +590,4 @@ interface WindshieldMist {
584
590
  }
585
591
  declare function createWindshieldMist(THREE: MistThree, built: BuiltVehicle): WindshieldMist;
586
592
 
587
- export { type BodyEvent, type BodyThree, BuiltVehicle, CAR_RECORDED_RPM, CAR_START_RUN_STOP, type CabinSmoke, DASHBOARD_LOOK, type DashboardOptions, type DashboardReading, type EngineBudget, type EngineBudgetOptions, type EngineLayerSetting, type EngineMixInput, EngineProfile, LAMP_RULES, LITE_CLASSES, type LampSwitch, type LiteClass, type LiteFusion, MIST_RULES, type MistThree, PRUNE_BELOW, VEHICLE_LOD_DISTANCE, VEHICLE_LOOPS, VEHICLE_LOOP_FALLOFF, VEHICLE_PRELOAD_SOUNDS, VEHICLE_SAMPLE_ALIASES, VEHICLE_SOUNDS, VEHICLE_SOUND_BANK, type VehicleBody, type VehicleBodyOptions, type VehicleDashboard, type VehicleLamps, type VehicleLod, type VehicleLodKit, type VehicleSound, type VehicleSoundFrame, VehicleSoundKeys, type VehicleSoundOptions, type VehicleSoundReading, type WheelRoll, type WheelRollThree, type WindowId, type WindshieldMist, classColor, classify, createCabinSmoke, createEngineBudget, createGearGuess, createVehicleBody, createVehicleDashboard, createVehicleLamps, createVehicleLod, createVehicleSound, createWheelRoll, createWindshieldMist, engineMix, firingHz, fuse, layerWeight, liteMaterials, liteMeshes, rpmShare };
593
+ export { type BodyEvent, type BodyThree, BuiltVehicle, CAR_RECORDED_RPM, CAR_START_RUN_STOP, type CabinSmoke, DASHBOARD_LOOK, type DashboardOptions, type DashboardReading, type EngineBudget, type EngineBudgetOptions, type EngineLayerSetting, type EngineMixInput, EngineProfile, LAMP_RULES, LITE_CLASSES, type LampSwitch, type LiteClass, type LiteFusion, MIST_RULES, type MistThree, PRUNE_BELOW, VEHICLE_LOD_DISTANCE, VEHICLE_LOOPS, VEHICLE_LOOP_FALLOFF, VEHICLE_PRELOAD_SOUNDS, VEHICLE_SAMPLE_ALIASES, VEHICLE_SOUNDS, VEHICLE_SOUND_BANK, type VehicleBody, type VehicleBodyOptions, type VehicleDashboard, type VehicleLamps, type VehicleLod, type VehicleLodKit, type VehicleSound, type VehicleSoundFrame, VehicleSoundKeys, type VehicleSoundOptions, type VehicleSoundReading, type WheelRoll, type WheelRollThree, type WindowId, type WindshieldMist, classColor, classify, createCabinSmoke, createEngineBudget, createGearGuess, createVehicleBody, createVehicleDashboard, createVehicleLamps, createVehicleLod, createVehicleSound, createWheelRoll, createWindshieldMist, engineMix, firingHz, fuse, layerWeight, liteMaterials, liteMeshes, rpmShare, slideOfGrip };
@@ -74,7 +74,8 @@ var GameVehiclesThree = (() => {
74
74
  liteMeshes: () => liteMeshes,
75
75
  loadProvingModule: () => loadProvingModule,
76
76
  loadVehiclesTestModule: () => loadVehiclesTestModule,
77
- rpmShare: () => rpmShare
77
+ rpmShare: () => rpmShare,
78
+ slideOfGrip: () => slideOfGrip
78
79
  });
79
80
 
80
81
  // ../game-contracts/dist/index.js
@@ -46400,6 +46401,7 @@ var GameVehiclesThree = (() => {
46400
46401
 
46401
46402
  // src/audio/vehicle-sound.ts
46402
46403
  var clamp012 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
46404
+ var slideOfGrip = (usage) => clamp012((Math.abs(usage) - 0.9) / 0.1);
46403
46405
  function createVehicleSound(audio, options = {}) {
46404
46406
  const profile = options.profile ?? CAR_ENGINE;
46405
46407
  const keys = { ...DEFAULT_VEHICLE_SOUND_KEYS, ...options.sounds };
@@ -48738,7 +48740,7 @@ var GameVehiclesThree = (() => {
48738
48740
  position: [driver.state.x, 0.5, driver.state.z],
48739
48741
  speed,
48740
48742
  throttle: input.throttle,
48741
- ...semiState ? { rpm: semiState.rpm, slip: Math.max(0, ...semiState.slip.map(Math.abs)) } : { slip: braking && speed > 3 ? 0.6 : 0 },
48743
+ ...semiState ? { rpm: semiState.rpm, slip: Math.max(0, ...semiState.slip.map(slideOfGrip)) } : { slip: braking && speed > 3 ? 0.6 : 0 },
48742
48744
  surface: /dirt|gravel|sand|grass|mud/.test(settings.surface) ? "dirt" : "asphalt",
48743
48745
  brake: input.brake
48744
48746
  });
@@ -49122,8 +49124,10 @@ var GameVehiclesThree = (() => {
49122
49124
  let done = false;
49123
49125
  let nextSample = 0;
49124
49126
  let carry = 0;
49127
+ let last = { throttle: 0, brake: 0, steer: 0, handbrake: false };
49125
49128
  const tick = (h) => {
49126
49129
  const input = procedure.input(driver.state, time, memo);
49130
+ last = input;
49127
49131
  driver.step(input, h, world);
49128
49132
  time += h;
49129
49133
  if (time >= nextSample) {
@@ -49147,6 +49151,9 @@ var GameVehiclesThree = (() => {
49147
49151
  get trace() {
49148
49152
  return trace;
49149
49153
  },
49154
+ get input() {
49155
+ return last;
49156
+ },
49150
49157
  step(dt) {
49151
49158
  carry += dt;
49152
49159
  while (!done && carry >= fixed) {
@@ -49954,6 +49961,7 @@ var GameVehiclesThree = (() => {
49954
49961
  let sparkAgain = 0;
49955
49962
  let wiresBefore = 0;
49956
49963
  let gas = 0;
49964
+ let pedal = 0;
49957
49965
  const systems = createVehicleSystems();
49958
49966
  const context = o.built.context;
49959
49967
  const destructible = o.kit && context ? createVehicleDestructible(o.kit, context, { id: "driven", frame: o.built.group }) : null;
@@ -50047,9 +50055,13 @@ var GameVehiclesThree = (() => {
50047
50055
  get throttle() {
50048
50056
  return gas;
50049
50057
  },
50058
+ get brake() {
50059
+ return pedal;
50060
+ },
50050
50061
  step(dt) {
50051
50062
  const input = controls.input(dt, driver);
50052
50063
  gas = input.throttle;
50064
+ pedal = input.brake;
50053
50065
  if (input.start && sounds.starter) play(sounds.starter);
50054
50066
  const engine = driver.step(input, dt).events;
50055
50067
  controls.after(driver, dt);
@@ -51170,7 +51182,18 @@ var GameVehiclesThree = (() => {
51170
51182
  steer = p.driver.state.steerAngle;
51171
51183
  if (p.time > 9) parking = null;
51172
51184
  }
51173
- if (car) engine?.update({ dt, position: [car.built.group.position.x, 0.5, car.built.group.position.z], speed, throttle: run ? 1 : driving?.throttle ?? 0, rpm: driving ? driving.driver.state.rpm : void 0 });
51185
+ if (car) {
51186
+ const semi = run?.driver.state ?? driving?.driver.state;
51187
+ const asked = run ? run.input : { throttle: driving?.throttle ?? 0, brake: driving?.brake ?? 0 };
51188
+ engine?.update({
51189
+ dt,
51190
+ position: [car.built.group.position.x, 0.5, car.built.group.position.z],
51191
+ speed,
51192
+ throttle: asked.throttle,
51193
+ brake: asked.brake,
51194
+ ...semi ? { rpm: semi.rpm, slip: Math.max(0, ...semi.slip.map(slideOfGrip)) } : {}
51195
+ });
51196
+ }
51174
51197
  const f = frameOf(speed);
51175
51198
  if (f && rig.vehicle && settings.camera !== "room") rig.vehicle.update(rig.camera, f, dt);
51176
51199
  if (f && rig.vehicle) for (const m of rig.mirrors) rig.vehicle.placeMirror(m.camera, aimed(m.pose), f);