This feature is supported as of BeamNG.tech and .drive version 0.34 to latest.
Electrics is a section in Jbeam that allows for defining custom electrics values and assigning smoothers to them. It consists of 2 tables: customValues, which defines the name of the value and the function it is derived from, and smoothers, which assigns smoothers to values by name. Custom electrics values can be used for gradual transitions between binary inputs, for example for sealed beam headlights which smoothly turn on and off. They can also be used to add or multiply several inputs together, which can be used to achieve the effect of vehicle lights dimming when the electrical system of the car is under load, for example when using the starter.
"electrics": {
"customValues": [
["electricsName", "electricsFunction"],
["customValue1","electrics.existingValue1 * electrics.existingValue2"],
]
"smoothers": [
["electricsName", "smootherType", "params"],
["customValue1","temporalNonLinear", [10,10]],
]
}
The whole electrics section can exist inside of the components section and it will still be read normally. This is useful for deep table merging, such as adding a new custom value or smoother in a different part of the vehicle.
"components": {
"electrics": {
"customValues": [
["electricsName", "electricsFunction"],
["customValue1","electrics.existingValue1 * electrics.existingValue2"],
]
"smoothers": [
["electricsName", "smootherType", "params"],
["customValue1","temporalNonLinear", [10,10]],
]
}
}
Example expression:
"(electrics.lowhighbeam + electrics.brakelight_signal_L) * electrics.electricalLoadCoef"
The expression cannot contain assignments, or single standalone ‘=’ signs! It can contain:
Example expression with functions:
"pwm(sign(electrics.lightbar), 0.5, 0.5) * electrics.electricalLoadCoef"
Supported smoother types:
For exponential smoothing, usually only the first one is used:
For temporal smoothing, usually the first two are used:
The most useful type of smoother is a temporal non-linear one with in and out rates declared, used for the on-off transitions of halogen and sealed beam lights:
"smoothers": [
["electricsName", "smootherType", "params"],
["lowbeam_filament","temporalNonLinear", [10,10]],
["highbeam_filament","temporalNonLinear", [10,10]],
]
Some electrics values have an exponential smoother by default:
wheelspeed, gear_A, rpm, lights, turnsignal, airspeed, airflowspeed, altitude
fuel, oiltemp, watertemp
Custom electrics values for simple halogen and sealed beam lamps which smoothly turn on and off and react to electrical system load.
"electrics": {
"customValues": [
["electricsName", "electricsFunction"],
["lowbeam_filament","electrics.lowbeam * electrics.electricalLoadCoef"],
["highbeam_filament","electrics.highbeam * electrics.electricalLoadCoef"],
["lowhighbeam_filament","electrics.lowhighbeam * electrics.electricalLoadCoef"],
["taillight_filament","electrics.lowhighbeam * electrics.electricalLoadCoef"],
["brakelight_filament","electrics.brakelights * electrics.electricalLoadCoef"],
["brakelight_signal_L_filament","electrics.brakelight_signal_L * electrics.electricalLoadCoef"],
["brakelight_signal_R_filament","electrics.brakelight_signal_R * electrics.electricalLoadCoef"],
["lowhighbeam_signal_L_filament","electrics.lowhighbeam_signal_L * electrics.electricalLoadCoef"],
["lowhighbeam_signal_R_filament","electrics.lowhighbeam_signal_R * electrics.electricalLoadCoef"],
["reverselight_filament","electrics.reverse * electrics.electricalLoadCoef"],
["foglight_filament","electrics.fog * electrics.electricalLoadCoef"],
["signal_L_filament","electrics.signal_L * electrics.electricalLoadCoef"],
["signal_R_filament","electrics.signal_R * electrics.electricalLoadCoef"],
]
"smoothers": [
["electricsName", "smootherType", "params"],
["lowbeam_filament","temporalNonLinear", [10,10]],
["highbeam_filament","temporalNonLinear", [10,10]],
["lowhighbeam_filament","temporalNonLinear", [10,10]],
["taillight_signal_L_filament","temporalNonLinear", [15,15]],
["taillight_signal_R_filament","temporalNonLinear", [15,15]],
["taillight_filament","temporalNonLinear", [10,10]],
["brakelight_filament","temporalNonLinear", [10,10]],
["brakelight_signal_L_filament","temporalNonLinear", [15,15]],
["brakelight_signal_R_filament","temporalNonLinear", [15,15]],
["lowhighbeam_signal_L_filament","temporalNonLinear", [15,15]],
["lowhighbeam_signal_R_filament","temporalNonLinear", [15,15]],
["reverselight_filament","temporalNonLinear", [10,10]],
["foglight_filament","temporalNonLinear", [10,10]],
["signal_L_filament","temporalNonLinear", [15,15]],
["signal_R_filament","temporalNonLinear", [15,15]],
]
}
Custom electrics values for combined halogen function lights.
"electrics": {
"customValues": [
["electricsName", "electricsFunction"],
["lowhighBrakeSignal_L_filament","(electrics.lowhighbeam + electrics.brakelight_signal_L)*electrics.electricalLoadCoef"],
["lowhighBrakeSignal_R_filament","(electrics.lowhighbeam + electrics.brakelight_signal_R)*electrics.electricalLoadCoef"],
]
"smoothers": [
["electricsName", "smootherType", "params"],
["lowhighBrakeSignal_L_filament","temporalNonLinear", [5,5]],
["lowhighBrakeSignal_R_filament","temporalNonLinear", [5,5]],
]
}
Custom electrics value for an animated halogen police flasher that fades in and out constantly when the light bar is turned on.
"electrics": {
"customValues": [
["electricsName", "electricsFunction"],
["police_flasher_filament","pwm(sign(electrics.lightbar), 0.5, 0.5) * electrics.electricalLoadCoef"],
]
"smoothers": [
["electricsName", "smootherType", "params"],
["police_flasher_filament","temporalNonLinear", [4,4]],
]
}