CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
BlueprintLibary
WeatherJsonUtils.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include "CoreMinimal.h"
10
#include "
Carla/Weather/WeatherParameters.h
"
11
#include "Kismet/BlueprintFunctionLibrary.h"
12
#include "Misc/Paths.h"
13
#include "WeatherJsonUtils.generated.h"
14
15
// Sun position only -- everything a "time of day" preset (Sunrise, Noon,
16
// Sunset, Night...) needs to say.
17
USTRUCT(BlueprintType)
18
struct
FWeatherTimePreset
19
{
20
GENERATED_BODY()
21
22
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"360.0"
))
23
float
SunAzimuthAngle
= 0.0f;
24
25
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"-90.0"
, ClampMax =
"90.0"
))
26
float
SunAltitudeAngle
= 75.0f;
27
};
28
29
// Everything else in FWeatherParameters -- what a "weather condition" preset
30
// (Clear, Cloudy, Rain...) means to set, independent of time of day.
31
USTRUCT(BlueprintType)
32
struct
FWeatherConditionPreset
33
{
34
GENERATED_BODY()
35
36
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"100.0"
))
37
float
Cloudiness
= 0.0f;
38
39
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"100.0"
))
40
float
Precipitation
= 0.0f;
41
42
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"100.0"
))
43
float
PrecipitationDeposits
= 0.0f;
44
45
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"100.0"
))
46
float
WindIntensity
= 0.35f;
47
48
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
))
49
float
FogDensity
= 0.0f;
50
51
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
))
52
float
FogDistance
= 0.0f;
53
54
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
))
55
float
FogFalloff
= 0.2f;
56
57
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"100.0"
))
58
float
Wetness
= 0.0f;
59
60
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"100.0"
))
61
float
ScatteringIntensity
= 0.0f;
62
63
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"5.0"
))
64
float
MieScatteringScale
= 0.0f;
65
66
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin =
"0.0"
, ClampMax =
"2.0"
))
67
float
RayleighScatteringScale
= 0.0331f;
68
};
69
70
UCLASS()
71
class CARLA_API
UWeatherJsonUtils
: public
UBlueprintFunctionLibrary
72
{
73
GENERATED_BODY()
74
75
public
:
76
77
// Both catalogs -- every named time preset and every named condition
78
// preset -- live together in one file, Config/Weather/Presets.json:
79
// { "time": { "Noon": {...}, "Town10_dusk": {...} },
80
// "conditions": { "Clear": {...}, "Rain": {...} } }
81
// A custom preset invented while tuning one map (e.g. "Town10_dusk")
82
// lands in the same shared catalog, so it can be picked for any other
83
// map's default too -- nothing is namespaced per-map.
84
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
85
static
bool
SaveTimePreset
(
const
FWeatherTimePreset
& Preset,
const
FString& Name);
86
87
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
88
static
bool
LoadTimePreset
(UPARAM(ref)
FWeatherTimePreset
& OutPreset,
const
FString& Name);
89
90
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
91
static
bool
SaveConditionPreset
(
const
FWeatherConditionPreset
& Preset,
const
FString& Name);
92
93
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
94
static
bool
LoadConditionPreset
(UPARAM(ref)
FWeatherConditionPreset
& OutPreset,
const
FString& Name);
95
96
// Names of every saved preset in each catalog. Back the "Get Options"
97
// dropdowns on ASkyBase::TimePresetName / ConditionPresetName.
98
UFUNCTION(BlueprintCallable, BlueprintPure, Category =
"Weather|JSON"
)
99
static
TArray<FString>
GetAvailableTimePresetNames
();
100
101
UFUNCTION(BlueprintCallable, BlueprintPure, Category =
"Weather|JSON"
)
102
static
TArray<FString>
GetAvailableConditionPresetNames
();
103
104
// Applies TimePreset's sun position and ConditionPreset's everything-else
105
// on top of Base (so fields neither preset touches -- there aren't any
106
// today, but future ones -- keep whatever Base already had).
107
UFUNCTION(BlueprintCallable, BlueprintPure, Category =
"Weather|JSON"
)
108
static
FWeatherParameters
MergeWeatherPresets
(
109
const
FWeatherParameters
& Base,
110
const
FWeatherTimePreset
& TimePreset,
111
const
FWeatherConditionPreset
& ConditionPreset);
112
113
// Per-map default preset names, read from MapDefaults.json:
114
// { "Town10HD_Opt": { "time": "Noon", "condition": "Clear" } }
115
// Returns false if the map has no entry.
116
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
117
static
bool
GetMapDefaultPresetNames
(
const
FString& MapName, FString& OutTimeName, FString& OutConditionName);
118
119
// Writes/overwrites MapName's entry in MapDefaults.json as a reference to
120
// two named catalog presets.
121
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
122
static
bool
SetMapDefaultPresetNames
(
const
FString& MapName,
const
FString& TimeName,
const
FString& ConditionName);
123
124
// MapName's entry, resolved regardless of which of the two shapes
125
// MapDefaults.json holds it in:
126
// { "Town10HD_Opt": { "time": "Noon", "condition": "Clear" } } -- named presets, merged onto Base
127
// { "Town10HD_Opt": { "sunAzimuthAngle": 180, "cloudiness": 5, ... } } -- a full inline snapshot
128
// A map's hand-tuned one-off setup doesn't need a named preset invented
129
// just to be reachable as its default -- and doesn't pollute the shared
130
// Presets.json catalog other maps pick from. Returns false if the map has
131
// no entry, or a named-preset entry names a preset that no longer exists.
132
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
133
static
bool
GetMapDefaultWeather
(
const
FString& MapName,
const
FWeatherParameters
& Base, UPARAM(ref)
FWeatherParameters
& OutWeather);
134
135
// Writes/overwrites MapName's entry in MapDefaults.json as a full inline
136
// snapshot of Weather -- no named preset involved on either side.
137
UFUNCTION(BlueprintCallable, Category =
"Weather|JSON"
)
138
static
bool
SetMapDefaultWeather
(
const
FString& MapName,
const
FWeatherParameters
&
Weather
);
139
140
static
FString
GetPresetsPath
()
141
{
142
return
FPaths::ProjectContentDir() / TEXT(
"Carla/Config/Weather/Presets.json"
);
143
}
144
145
static
FString
GetMapDefaultsPath
()
146
{
147
return
FPaths::ProjectContentDir() / TEXT(
"Carla/Config/Weather/MapDefaults.json"
);
148
}
149
};
CarlaRecorderPacketId::Weather
@ Weather
Definition
CarlaRecorder.h:75
WeatherParameters.h
UBlueprintFunctionLibrary
UWeatherJsonUtils
Definition
WeatherJsonUtils.h:72
UWeatherJsonUtils::MergeWeatherPresets
static FWeatherParameters MergeWeatherPresets(const FWeatherParameters &Base, const FWeatherTimePreset &TimePreset, const FWeatherConditionPreset &ConditionPreset)
Definition
WeatherJsonUtils.cpp:125
UWeatherJsonUtils::SaveConditionPreset
static bool SaveConditionPreset(const FWeatherConditionPreset &Preset, const FString &Name)
Definition
WeatherJsonUtils.cpp:105
UWeatherJsonUtils::GetMapDefaultWeather
static bool GetMapDefaultWeather(const FString &MapName, const FWeatherParameters &Base, UPARAM(ref) FWeatherParameters &OutWeather)
Definition
WeatherJsonUtils.cpp:173
UWeatherJsonUtils::GetPresetsPath
static FString GetPresetsPath()
Definition
WeatherJsonUtils.h:140
UWeatherJsonUtils::GetAvailableConditionPresetNames
static TArray< FString > GetAvailableConditionPresetNames()
Definition
WeatherJsonUtils.cpp:120
UWeatherJsonUtils::GetMapDefaultPresetNames
static bool GetMapDefaultPresetNames(const FString &MapName, FString &OutTimeName, FString &OutConditionName)
Definition
WeatherJsonUtils.cpp:150
UWeatherJsonUtils::LoadConditionPreset
static bool LoadConditionPreset(UPARAM(ref) FWeatherConditionPreset &OutPreset, const FString &Name)
Definition
WeatherJsonUtils.cpp:110
UWeatherJsonUtils::SaveTimePreset
static bool SaveTimePreset(const FWeatherTimePreset &Preset, const FString &Name)
Definition
WeatherJsonUtils.cpp:95
UWeatherJsonUtils::SetMapDefaultWeather
static bool SetMapDefaultWeather(const FString &MapName, const FWeatherParameters &Weather)
Definition
WeatherJsonUtils.cpp:201
UWeatherJsonUtils::GetAvailableTimePresetNames
static TArray< FString > GetAvailableTimePresetNames()
Definition
WeatherJsonUtils.cpp:115
UWeatherJsonUtils::GetMapDefaultsPath
static FString GetMapDefaultsPath()
Definition
WeatherJsonUtils.h:145
UWeatherJsonUtils::LoadTimePreset
static bool LoadTimePreset(UPARAM(ref) FWeatherTimePreset &OutPreset, const FString &Name)
Definition
WeatherJsonUtils.cpp:100
UWeatherJsonUtils::SetMapDefaultPresetNames
static bool SetMapDefaultPresetNames(const FString &MapName, const FString &TimeName, const FString &ConditionName)
Definition
WeatherJsonUtils.cpp:161
FWeatherConditionPreset
Definition
WeatherJsonUtils.h:33
FWeatherConditionPreset::Cloudiness
float Cloudiness
Definition
WeatherJsonUtils.h:37
FWeatherConditionPreset::RayleighScatteringScale
float RayleighScatteringScale
Definition
WeatherJsonUtils.h:67
FWeatherConditionPreset::FogDistance
float FogDistance
Definition
WeatherJsonUtils.h:52
FWeatherConditionPreset::FogDensity
float FogDensity
Definition
WeatherJsonUtils.h:49
FWeatherConditionPreset::Precipitation
float Precipitation
Definition
WeatherJsonUtils.h:40
FWeatherConditionPreset::MieScatteringScale
float MieScatteringScale
Definition
WeatherJsonUtils.h:64
FWeatherConditionPreset::PrecipitationDeposits
float PrecipitationDeposits
Definition
WeatherJsonUtils.h:43
FWeatherConditionPreset::Wetness
float Wetness
Definition
WeatherJsonUtils.h:58
FWeatherConditionPreset::WindIntensity
float WindIntensity
Definition
WeatherJsonUtils.h:46
FWeatherConditionPreset::ScatteringIntensity
float ScatteringIntensity
Definition
WeatherJsonUtils.h:61
FWeatherConditionPreset::FogFalloff
float FogFalloff
Definition
WeatherJsonUtils.h:55
FWeatherParameters
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Weather/WeatherParameters.h:13
FWeatherTimePreset
Definition
WeatherJsonUtils.h:19
FWeatherTimePreset::SunAltitudeAngle
float SunAltitudeAngle
Definition
WeatherJsonUtils.h:26
FWeatherTimePreset::SunAzimuthAngle
float SunAzimuthAngle
Definition
WeatherJsonUtils.h:23
Generated by
1.18.0