From a41bf95afdec533aee2c85051d24d7b56cafa215 Mon Sep 17 00:00:00 2001 From: Marc Garcia Puig Date: Mon, 13 Jan 2020 19:10:20 +0100 Subject: [PATCH] Added more weather attributes --- Docs/python_api_tutorial.md | 2 +- .../source/carla/rpc/WeatherParameters.cpp | 32 ++++++------- LibCarla/source/carla/rpc/WeatherParameters.h | 45 ++++++++++++++----- PythonAPI/carla/source/libcarla/Weather.cpp | 16 ++++--- PythonAPI/examples/dynamic_weather.py | 2 +- .../Carla/Source/Carla/Weather/Weather.cpp | 5 ++- .../Source/Carla/Weather/WeatherParameters.h | 11 ++++- 7 files changed, 76 insertions(+), 37 deletions(-) diff --git a/Docs/python_api_tutorial.md b/Docs/python_api_tutorial.md index fb84754de..afa824bdb 100644 --- a/Docs/python_api_tutorial.md +++ b/Docs/python_api_tutorial.md @@ -349,7 +349,7 @@ object ```py weather = carla.WeatherParameters( - cloudyness=80.0, + cloudiness=80.0, precipitation=30.0, sun_altitude_angle=70.0) diff --git a/LibCarla/source/carla/rpc/WeatherParameters.cpp b/LibCarla/source/carla/rpc/WeatherParameters.cpp index b867c2059..fd10e1937 100644 --- a/LibCarla/source/carla/rpc/WeatherParameters.cpp +++ b/LibCarla/source/carla/rpc/WeatherParameters.cpp @@ -11,22 +11,22 @@ namespace rpc { using WP = WeatherParameters; - // cloudyness precip. prec.dep. wind azimuth altitude - WP WP::Default = { -1.0f, -1.0f, -1.0f, -1.00f, -1.0f, -1.0f}; - WP WP::ClearNoon = { 15.0f, 0.0f, 0.0f, 0.35f, 0.0f, 75.0f}; - WP WP::CloudyNoon = { 80.0f, 0.0f, 0.0f, 0.35f, 0.0f, 75.0f}; - WP WP::WetNoon = { 20.0f, 0.0f, 50.0f, 0.35f, 0.0f, 75.0f}; - WP WP::WetCloudyNoon = { 80.0f, 0.0f, 50.0f, 0.35f, 0.0f, 75.0f}; - WP WP::MidRainyNoon = { 80.0f, 30.0f, 50.0f, 0.40f, 0.0f, 75.0f}; - WP WP::HardRainNoon = { 90.0f, 60.0f, 100.0f, 1.00f, 0.0f, 75.0f}; - WP WP::SoftRainNoon = { 70.0f, 15.0f, 50.0f, 0.35f, 0.0f, 75.0f}; - WP WP::ClearSunset = { 15.0f, 0.0f, 0.0f, 0.35f, 0.0f, 15.0f}; - WP WP::CloudySunset = { 80.0f, 0.0f, 0.0f, 0.35f, 0.0f, 15.0f}; - WP WP::WetSunset = { 20.0f, 0.0f, 50.0f, 0.35f, 0.0f, 15.0f}; - WP WP::WetCloudySunset = { 90.0f, 0.0f, 50.0f, 0.35f, 0.0f, 15.0f}; - WP WP::MidRainSunset = { 80.0f, 30.0f, 50.0f, 0.40f, 0.0f, 15.0f}; - WP WP::HardRainSunset = { 80.0f, 60.0f, 100.0f, 1.00f, 0.0f, 15.0f}; - WP WP::SoftRainSunset = { 90.0f, 15.0f, 50.0f, 0.35f, 0.0f, 15.0f}; + // cloudiness precip. prec.dep. wind azimuth altitude fog dens. fog dist wetness + WP WP::Default = { -1.0f, -1.0f, -1.0f, -1.00f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}; + WP WP::ClearNoon = { 15.0f, 0.0f, 0.0f, 0.35f, 0.0f, 75.0f, 0.0f, 0.0f, 0.0f}; + WP WP::CloudyNoon = { 80.0f, 0.0f, 0.0f, 0.35f, 0.0f, 75.0f, 0.0f, 0.0f, 0.0f}; + WP WP::WetNoon = { 20.0f, 0.0f, 50.0f, 0.35f, 0.0f, 75.0f, 0.0f, 0.0f, 0.0f}; + WP WP::WetCloudyNoon = { 80.0f, 0.0f, 50.0f, 0.35f, 0.0f, 75.0f, 0.0f, 0.0f, 0.0f}; + WP WP::MidRainyNoon = { 80.0f, 30.0f, 50.0f, 0.40f, 0.0f, 75.0f, 0.0f, 0.0f, 0.0f}; + WP WP::HardRainNoon = { 90.0f, 60.0f, 100.0f, 1.00f, 0.0f, 75.0f, 0.0f, 0.0f, 0.0f}; + WP WP::SoftRainNoon = { 70.0f, 15.0f, 50.0f, 0.35f, 0.0f, 75.0f, 0.0f, 0.0f, 0.0f}; + WP WP::ClearSunset = { 15.0f, 0.0f, 0.0f, 0.35f, 0.0f, 15.0f, 0.0f, 0.0f, 0.0f}; + WP WP::CloudySunset = { 80.0f, 0.0f, 0.0f, 0.35f, 0.0f, 15.0f, 0.0f, 0.0f, 0.0f}; + WP WP::WetSunset = { 20.0f, 0.0f, 50.0f, 0.35f, 0.0f, 15.0f, 0.0f, 0.0f, 0.0f}; + WP WP::WetCloudySunset = { 90.0f, 0.0f, 50.0f, 0.35f, 0.0f, 15.0f, 0.0f, 0.0f, 0.0f}; + WP WP::MidRainSunset = { 80.0f, 30.0f, 50.0f, 0.40f, 0.0f, 15.0f, 0.0f, 0.0f, 0.0f}; + WP WP::HardRainSunset = { 80.0f, 60.0f, 100.0f, 1.00f, 0.0f, 15.0f, 0.0f, 0.0f, 0.0f}; + WP WP::SoftRainSunset = { 90.0f, 15.0f, 50.0f, 0.35f, 0.0f, 15.0f, 0.0f, 0.0f, 0.0f}; } // namespace rpc } // namespace carla diff --git a/LibCarla/source/carla/rpc/WeatherParameters.h b/LibCarla/source/carla/rpc/WeatherParameters.h index fd2587c49..60a9511e7 100644 --- a/LibCarla/source/carla/rpc/WeatherParameters.h +++ b/LibCarla/source/carla/rpc/WeatherParameters.h @@ -42,44 +42,59 @@ namespace rpc { WeatherParameters() = default; WeatherParameters( - float in_cloudyness, + float in_cloudiness, float in_precipitation, float in_precipitation_deposits, float in_wind_intensity, float in_sun_azimuth_angle, - float in_sun_altitude_angle) - : cloudyness(in_cloudyness), + float in_sun_altitude_angle, + float in_fog_density, + float in_fog_distance, + float in_wetness) + : cloudiness(in_cloudiness), precipitation(in_precipitation), precipitation_deposits(in_precipitation_deposits), wind_intensity(in_wind_intensity), sun_azimuth_angle(in_sun_azimuth_angle), - sun_altitude_angle(in_sun_altitude_angle) {} + sun_altitude_angle(in_sun_altitude_angle), + fog_density(in_fog_density), + fog_distance(in_fog_distance), + wetness(in_wetness) {} - float cloudyness = 0.0f; + float cloudiness = 0.0f; float precipitation = 0.0f; float precipitation_deposits = 0.0f; float wind_intensity = 0.0f; float sun_azimuth_angle = 0.0f; float sun_altitude_angle = 0.0f; + float fog_density = 0.0f; + float fog_distance = 0.0f; + float wetness = 0.0f; #ifdef LIBCARLA_INCLUDED_FROM_UE4 WeatherParameters(const FWeatherParameters &Weather) - : cloudyness(Weather.Cloudyness), + : cloudiness(Weather.Cloudiness), precipitation(Weather.Precipitation), precipitation_deposits(Weather.PrecipitationDeposits), wind_intensity(Weather.WindIntensity), sun_azimuth_angle(Weather.SunAzimuthAngle), - sun_altitude_angle(Weather.SunAltitudeAngle) {} + sun_altitude_angle(Weather.SunAltitudeAngle), + fog_density(Weather.FogDensity), + fog_distance(Weather.FogDistance), + wetness(Weather.Wetness) {} operator FWeatherParameters() const { FWeatherParameters Weather; - Weather.Cloudyness = cloudyness; + Weather.Cloudiness = cloudiness; Weather.Precipitation = precipitation; Weather.PrecipitationDeposits = precipitation_deposits; Weather.WindIntensity = wind_intensity; Weather.SunAzimuthAngle = sun_azimuth_angle; Weather.SunAltitudeAngle = sun_altitude_angle; + Weather.FogDensity = fog_density; + Weather.FogDistance = fog_distance; + Weather.Wetness = wetness; return Weather; } @@ -87,12 +102,15 @@ namespace rpc { bool operator!=(const WeatherParameters &rhs) const { return - cloudyness != rhs.cloudyness || + cloudiness != rhs.cloudiness || precipitation != rhs.precipitation || precipitation_deposits != rhs.precipitation_deposits || wind_intensity != rhs.wind_intensity || sun_azimuth_angle != rhs.sun_azimuth_angle || - sun_altitude_angle != rhs.sun_altitude_angle; + sun_altitude_angle != rhs.sun_altitude_angle || + fog_density != rhs.fog_density || + fog_distance != rhs.fog_distance || + wetness != rhs.wetness; } bool operator==(const WeatherParameters &rhs) const { @@ -100,12 +118,15 @@ namespace rpc { } MSGPACK_DEFINE_ARRAY( - cloudyness, + cloudiness, precipitation, precipitation_deposits, wind_intensity, sun_azimuth_angle, - sun_altitude_angle); + sun_altitude_angle, + fog_density, + fog_distance, + wetness); }; } // namespace rpc diff --git a/PythonAPI/carla/source/libcarla/Weather.cpp b/PythonAPI/carla/source/libcarla/Weather.cpp index 185966e63..b2d73e544 100644 --- a/PythonAPI/carla/source/libcarla/Weather.cpp +++ b/PythonAPI/carla/source/libcarla/Weather.cpp @@ -12,7 +12,7 @@ namespace carla { namespace rpc { std::ostream &operator<<(std::ostream &out, const WeatherParameters &weather) { - out << "WeatherParameters(cloudyness=" << std::to_string(weather.cloudyness) + out << "WeatherParameters(cloudiness=" << std::to_string(weather.cloudiness) << ", precipitation=" << std::to_string(weather.precipitation) << ", precipitation_deposits=" << std::to_string(weather.precipitation_deposits) << ", wind_intensity=" << std::to_string(weather.wind_intensity) @@ -29,19 +29,25 @@ void export_weather() { namespace cr = carla::rpc; auto cls = class_("WeatherParameters") - .def(init( - (arg("cloudyness")=0.0f, + .def(init( + (arg("cloudiness")=0.0f, arg("precipitation")=0.0f, arg("precipitation_deposits")=0.0f, arg("wind_intensity")=0.0f, arg("sun_azimuth_angle")=0.0f, - arg("sun_altitude_angle")=0.0f))) - .def_readwrite("cloudyness", &cr::WeatherParameters::cloudyness) + arg("sun_altitude_angle")=0.0f, + arg("fog_density")=0.0f, + arg("fog_distance")=0.0f, + arg("wetness")=0.0f))) + .def_readwrite("cloudiness", &cr::WeatherParameters::cloudiness) .def_readwrite("precipitation", &cr::WeatherParameters::precipitation) .def_readwrite("precipitation_deposits", &cr::WeatherParameters::precipitation_deposits) .def_readwrite("wind_intensity", &cr::WeatherParameters::wind_intensity) .def_readwrite("sun_azimuth_angle", &cr::WeatherParameters::sun_azimuth_angle) .def_readwrite("sun_altitude_angle", &cr::WeatherParameters::sun_altitude_angle) + .def_readwrite("fog_density", &cr::WeatherParameters::fog_density) + .def_readwrite("fog_distance", &cr::WeatherParameters::fog_distance) + .def_readwrite("wetness", &cr::WeatherParameters::wetness) .def("__eq__", &cr::WeatherParameters::operator==) .def("__ne__", &cr::WeatherParameters::operator!=) .def(self_ns::str(self_ns::self)) diff --git a/PythonAPI/examples/dynamic_weather.py b/PythonAPI/examples/dynamic_weather.py index 4fd3e04da..01012f9b2 100755 --- a/PythonAPI/examples/dynamic_weather.py +++ b/PythonAPI/examples/dynamic_weather.py @@ -87,7 +87,7 @@ class Weather(object): def tick(self, delta_seconds): self._sun.tick(delta_seconds) self._storm.tick(delta_seconds) - self.weather.cloudyness = self._storm.clouds + self.weather.cloudiness = self._storm.clouds self.weather.precipitation = self._storm.rain self.weather.precipitation_deposits = self._storm.puddles self.weather.wind_intensity = self._storm.wind diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/Weather.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/Weather.cpp index cad5d3a17..c0f24166e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/Weather.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/Weather.cpp @@ -20,12 +20,15 @@ void AWeather::ApplyWeather(const FWeatherParameters &InWeather) #ifdef CARLA_WEATHER_EXTRA_LOG UE_LOG(LogCarla, Log, TEXT("Changing weather:")); - UE_LOG(LogCarla, Log, TEXT(" - Cloudyness = %.2f"), Weather.Cloudyness); + UE_LOG(LogCarla, Log, TEXT(" - Cloudiness = %.2f"), Weather.Cloudiness); UE_LOG(LogCarla, Log, TEXT(" - Precipitation = %.2f"), Weather.Precipitation); UE_LOG(LogCarla, Log, TEXT(" - PrecipitationDeposits = %.2f"), Weather.PrecipitationDeposits); UE_LOG(LogCarla, Log, TEXT(" - WindIntensity = %.2f"), Weather.WindIntensity); UE_LOG(LogCarla, Log, TEXT(" - SunAzimuthAngle = %.2f"), Weather.SunAzimuthAngle); UE_LOG(LogCarla, Log, TEXT(" - SunAltitudeAngle = %.2f"), Weather.SunAltitudeAngle); + UE_LOG(LogCarla, Log, TEXT(" - FogDensity = %.2f"), Weather.FogDensity); + UE_LOG(LogCarla, Log, TEXT(" - FogDistance = %.2f"), Weather.FogDistance); + UE_LOG(LogCarla, Log, TEXT(" - Wetness = %.2f"), Weather.Wetness); #endif // CARLA_WEATHER_EXTRA_LOG // Call the blueprint that actually changes the weather. diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/WeatherParameters.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/WeatherParameters.h index 1c6b49ec2..6f38d7cbe 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/WeatherParameters.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Weather/WeatherParameters.h @@ -14,7 +14,7 @@ struct CARLA_API FWeatherParameters GENERATED_BODY() UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0", UIMin = "0.0", UIMax = "100.0")) - float Cloudyness = 0.0f; + float Cloudiness = 0.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0", UIMin = "0.0", UIMax = "100.0")) float Precipitation = 0.0f; @@ -30,4 +30,13 @@ struct CARLA_API FWeatherParameters UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "-90.0", ClampMax = "90.0", UIMin = "-90.0", UIMax = "90.0")) float SunAltitudeAngle = 75.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0", UIMin = "0.0", UIMax = "100.0")) + float FogDensity = 0.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", UIMin = "0.0", UIMax = "1000.0")) + float FogDistance = 0.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0", UIMin = "0.0", UIMax = "100.0")) + float Wetness = 0.0f; };