载入中...
搜索中...
未找到
LightingRuntime.cpp
浏览该文件的文档.
2
3#include "graphics/Light.h"
4
5#include <utility>
6
7namespace eve::lighting_editing {
8namespace {
9
10Result<void> lightError(EditorStatus status, const char* rule, std::string message) {
11 return eve::editing::failed<void>(status, RuleId(rule), std::move(message));
12}
13
14const EditorValue::Array& array(const Light3DDocumentTarget& document, const char* path) {
15 return *document.value(path)->getIf<EditorValue::Array>();
16}
17
18double component(const EditorValue::Array& values, size_t index) { return *values[index].getIf<double>(); }
19
20} // namespace
21
23 if (!light)
24 return lightError(EditorStatus::Rejected, "editor.light.runtime-required", "Runtime Light3D is required");
25 const auto diagnostics = document.validate();
26 for (const EditorDiagnostic& diagnostic : diagnostics)
27 if (diagnostic.severity() == DiagnosticSeverity::Error)
28 return Result<void>::failure(eve::Status(EditorStatus::Rejected, diagnostics));
29 const auto& position = array(document, "transform.position");
30 const auto& direction = array(document, "transform.direction");
31 const auto& color = array(document, "light.color");
32 light->setType(*document.value("light.type")->getIf<std::string>());
33 light->setEnabled(*document.value("light.enabled")->getIf<bool>());
34 light->setPosition(static_cast<float>(component(position, 0)), static_cast<float>(component(position, 1)),
35 static_cast<float>(component(position, 2)));
36 light->setDirection(static_cast<float>(component(direction, 0)), static_cast<float>(component(direction, 1)),
37 static_cast<float>(component(direction, 2)));
38 light->setColor(static_cast<float>(component(color, 0)), static_cast<float>(component(color, 1)),
39 static_cast<float>(component(color, 2)),
40 static_cast<float>(*document.value("light.intensity")->getIf<double>()));
41 light->setRadius(static_cast<float>(*document.value("light.radius")->getIf<double>()));
42 if (const auto* angle = document.value("light.spot-angle")) {
43 if (const auto* degrees = angle->getIf<double>()) light->setSpotAngle(static_cast<float>(*degrees));
44 }
45 if (const auto* soft = document.value("light.spot-softness")) {
46 if (const auto* value = soft->getIf<double>()) light->setSpotSoftness(static_cast<float>(*value));
47 }
48 light->setCastShadow(*document.value("shadow.cast")->getIf<bool>());
49 if (const auto* method = document.value("shadow.method")) {
50 if (const auto* name = method->getIf<std::string>()) light->setShadowMethod(*name);
51 }
52 light->setShadowBias(static_cast<float>(*document.value("shadow.bias")->getIf<double>()));
53 light->setShadowStrength(static_cast<float>(*document.value("shadow.strength")->getIf<double>()));
54 light->setVolumetric(*document.value("volumetric.enabled")->getIf<bool>());
55 light->setVolumetricIntensity(static_cast<float>(*document.value("volumetric.intensity")->getIf<double>()));
56 if (const auto* only = document.value("volumetric.only")) {
57 if (const auto* flag = only->getIf<bool>()) light->setVolumetricOnly(*flag);
58 }
59 return eve::editing::applied<void>(diagnostics);
60}
61
62} // namespace eve::lighting_editing
double value
float degrees
Definition CardTypes.cpp:35
std::map< std::string, Var > values
std::uint16_t method
std::string message
float soft[4]
wgpu::PopErrorScopeStatus status
std::array< float, 3 > position
std::string name
std::string path
Definition PlayHost.cpp:110
RoadLaneDirection direction
Light3D::Data * light
uint32_t index
float angle
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.
Declarative 3D light. Collected by RenderSystem3D (max 8 per frame). type: "point" | "dir" | "spot" (...
Definition Light.h:191
Serializable property target matching graphics::Light3D.
std::vector< EditorDiagnostic > validate() const
Validate direction, shadow and point/directional cross-field rules.
Result< void > apply(const Light3DDocumentTarget &document, graphics::Light3D *light) const
Applies .
const EditorValue * value(const std::string &path) const
Read a typed runtime-neutral property value by path.
editing::RuleId RuleId
editing::Status EditorStatus
glm::vec4 color