CARLA
Loading...
Searching...
No Matches
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"
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.
17USTRUCT(BlueprintType)
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.
31USTRUCT(BlueprintType)
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
70UCLASS()
72{
73 GENERATED_BODY()
74
75public:
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};
static FString GetPresetsPath()
static FString GetMapDefaultsPath()