载入中...
搜索中...
未找到
EnvironmentWeatherRuntime.cpp
浏览该文件的文档.
2
3#include "weather/Weather.h"
4
5namespace eve::lighting_editing {
6namespace {
7
8double component(const EditorValue::Array& values, size_t index) { return *values[index].getIf<double>(); }
9
10} // namespace
11
13 weather::Weather* environment) const {
14 if (!environment)
15 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.environment.weather-required"),
16 "Runtime Weather environment is required");
17 const auto* mode = document.value("environment.mode")->getIf<std::string>();
18 if (!mode || *mode != "weather")
19 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.environment.mode-mismatch"),
20 "Environment document is not in weather mode");
21 const auto diagnostics = document.validate();
22 for (const EditorDiagnostic& diagnostic : diagnostics)
23 if (diagnostic.severity() == DiagnosticSeverity::Error)
24 return Result<void>::failure(eve::Status(EditorStatus::Rejected, diagnostics));
25 const auto& sky = *document.value("environment.sky-color")->getIf<EditorValue::Array>();
26 const auto& fog = *document.value("weather.fog-color")->getIf<EditorValue::Array>();
27 environment->setPreset(*document.value("weather.preset")->getIf<std::string>());
28 environment->setIntensity(static_cast<float>(*document.value("weather.intensity")->getIf<double>()));
29 environment->setWindSpeed(static_cast<float>(*document.value("weather.wind-speed")->getIf<double>()));
30 environment->setWindDirection(static_cast<float>(*document.value("weather.wind-direction")->getIf<double>()));
31 environment->setLightningEnabled(*document.value("weather.lightning")->getIf<bool>());
32 environment->setSkyColor(static_cast<float>(component(sky, 0)), static_cast<float>(component(sky, 1)),
33 static_cast<float>(component(sky, 2)));
34 environment->setFogColor(static_cast<float>(component(fog, 0)), static_cast<float>(component(fog, 1)),
35 static_cast<float>(component(fog, 2)));
36 environment->setFogDensity(static_cast<float>(*document.value("weather.fog-density")->getIf<double>()));
37 environment->setEnvironmentEnabled(*document.value("weather.environment-enabled")->getIf<bool>());
38 return eve::editing::applied<void>(diagnostics);
39}
40
41} // namespace eve::lighting_editing
std::map< std::string, Var > values
uint32_t index
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Structured status and zero or more diagnostics for an operation.
Definition Status.h:68
std::vector< Value > Array
const T * getIf() const
Return an immediately borrowed typed value.
Serializable shared environment target for static, DayNight and Weather modes.
std::vector< EditorDiagnostic > validate() const
Validate mode-dependent atmosphere and weather settings.
Result< void > applyWeather(const EnvironmentDocumentTarget &document, weather::Weather *environment) const
Applies weather.
const EditorValue * value(const std::string &path) const
Read a typed runtime-neutral property value by path.
Weather module — real-time precipitation / lightning / wind system.
Definition Weather.h:36
void setWindSpeed(float v)
Sets the wind speed.
Definition Weather.cpp:494
void setLightningEnabled(bool on)
Sets the lightning enabled.
Definition Weather.cpp:543
void setIntensity(float v)
Sets the intensity.
Definition Weather.cpp:489
void setSkyColor(float r, float g, float b)
Sets the sky color.
Definition Weather.cpp:558
void setFogDensity(float v)
Sets the fog density.
Definition Weather.cpp:575
void setEnvironmentEnabled(bool enabled)
Enable legacy weather-owned sky and directional lighting.
Definition Weather.cpp:578
void setPreset(const std::string &name)
Sets the preset.
Definition Weather.cpp:477
void setFogColor(float r, float g, float b)
Sets the fog color.
Definition Weather.cpp:568
void setWindDirection(float degrees)
Wind direction in degrees; 0 = toward +Z, 90 = toward -X.
Definition Weather.cpp:497
editing::RuleId RuleId