载入中...
搜索中...
未找到
VegetationFieldGizmo.cpp
浏览该文件的文档.
2
4
5#include <algorithm>
6#include <new>
7
8namespace eve::graphics_editing {
9namespace {
10
11Result<editing::GizmoSnapshot> failure(StatusCode code, DiagnosticCode diagnostic, std::string message,
12 std::string path = {}) {
14 Status(code, {Diagnostic::error(diagnostic, message, path, {},
15 "graphics_editing.vegetation_field_gizmo")}));
16}
17
18std::array<double, 4> channelColor(graphics::VegetationChannel channel, float opacity) {
19 const double alpha = std::clamp(double(opacity), 0.2, 1.0);
20 switch (channel) {
21 case graphics::VegetationChannel::Color: return {0.2, 0.85, 0.35, alpha};
22 case graphics::VegetationChannel::Extras: return {1.0, 0.55, 0.1, alpha};
23 case graphics::VegetationChannel::Motion: return {0.2, 0.65, 1.0, alpha};
24 case graphics::VegetationChannel::Vertex: return {0.75, 0.35, 1.0, alpha};
25 }
26 return {1.0, 1.0, 1.0, alpha};
27}
28
29} // namespace
30
32 std::string target, std::uint64_t expectedRevision, const graphics::VegetationField& field,
33 std::size_t maximumElements) const {
34 if (target.empty() || maximumElements == 0 || maximumElements > 100000)
36 "Vegetation field gizmo requires a target and a bounded element budget", "request");
37 if (field.revision() != expectedRevision)
39 "Vegetation field changed before gizmo generation", "revision");
40 auto elements = field.snapshotElements();
42 if (field.revision() != expectedRevision)
44 "Vegetation field changed while gizmo generation was reading it", "revision");
45 if (elements.value().size() > maximumElements)
47 "Vegetation field exceeds the gizmo element budget", "elements");
48 try {
51 result.target = std::move(target);
52 result.targetRevision = expectedRevision;
53 result.primitives.reserve(elements.value().size());
54 for (std::size_t i = 0; i < elements.value().size(); ++i) {
55 const auto& element = elements.value()[i];
57 primitive.id = "vegetation-field-" + std::to_string(i);
58 primitive.kind = element.shape == graphics::VegetationShape::Box ? "obb" : "ellipsoid";
59 primitive.position = {element.center.x, element.center.y, element.center.z};
60 primitive.size = {element.extents.x * 2.0, element.extents.y * 2.0, element.extents.z * 2.0};
61 primitive.color = channelColor(element.channel, element.opacity);
62 primitive.yaw = element.yaw;
63 primitive.dashed = !element.mask.pixels.empty();
64 result.primitives.push_back(std::move(primitive));
65 }
66 return Result<editing::GizmoSnapshot>::success(std::move(result));
67 } catch (const std::bad_alloc&) {
69 "Vegetation field gizmo allocation failed");
70 }
71}
72
73} // namespace eve::graphics_editing
LogicalId target
std::string message
DiagnosticCode code
std::string path
Definition PlayHost.cpp:110
std::string element
std::size_t elements
float opacity
float size
Definition TreeMesh.cpp:156
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Backend-independent, owning vegetation influence field. Single writer; concurrent const evaluation is...
Result< editing::GizmoSnapshot > build(std::string target, std::uint64_t expectedRevision, const graphics::VegetationField &field, std::size_t maximumElements=10000) const
Build one immutable gizmo from the field's owning element snapshot.
eve::StatusCode Status
VegetationChannel
Independent vegetation field channels; values use linear color and world units.
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
StatusCode
Stable outcome category for an operation.
Definition Status.h:27
Renderer-neutral wire primitive for authoring viewport overlays.
std::array< double, 3 > size
std::array< double, 3 > position
std::array< double, 4 > color
Immutable revision-tagged overlay snapshot consumed by any viewport renderer.
std::vector< GizmoPrimitive > primitives