载入中...
搜索中...
未找到
MeshVertexAxisGizmo.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <array>
5#include <cmath>
6#include <limits>
7
8namespace eve::procgen_editing {
9
11 double axisLength) const {
13 result.target = "procgen.meshVertexSelection";
14 result.targetRevision = session.revision();
15 auto center = session.selectedVertexCenterResult();
16 if (!center.ok() || !std::isfinite(axisLength) || axisLength <= 0.0) {
18 "axis gizmo requires a selected vertex and positive length",
19 "selection", {}, "procgen_editing.meshVertexAxisGizmo"));
20 return result;
21 }
22 const std::array<double, 3> position{center.value().x, center.value().y, center.value().z};
23 result.primitives.push_back(
24 {"mesh.axis.x", "arrow", position, {}, {1.0, 0.0, 0.0}, {1.0, 0.16, 0.12, 1.0}, 0.0, axisLength});
25 result.primitives.push_back(
26 {"mesh.axis.y", "arrow", position, {}, {0.0, 1.0, 0.0}, {0.18, 1.0, 0.28, 1.0}, 0.0, axisLength});
27 result.primitives.push_back(
28 {"mesh.axis.z", "arrow", position, {}, {0.0, 0.0, 1.0}, {0.18, 0.48, 1.0, 1.0}, 0.0, axisLength});
29 result.status = editing::Status::Applied;
30 return result;
31}
32
34 double originY, double originZ, double directionX,
35 double directionY, double directionZ) const {
36 const double rayLength = std::sqrt(directionX * directionX + directionY * directionY + directionZ * directionZ);
37 if (!std::isfinite(rayLength) || rayLength <= 1e-9)
39 "axis pick requires a finite non-zero ray", "ray", {},
40 "procgen_editing.meshVertexAxisGizmo"));
41 const std::array<double, 3> ray{directionX / rayLength, directionY / rayLength, directionZ / rayLength};
42 double bestDistance = std::numeric_limits<double>::infinity();
43 std::string best;
44 for (const auto& primitive : snapshot.primitives) {
45 if (primitive.kind != "arrow" || primitive.id.rfind("mesh.axis.", 0) != 0) continue;
46 const std::array<double, 3> a = primitive.position;
47 const std::array<double, 3> b{a[0] + primitive.direction[0] * primitive.length,
48 a[1] + primitive.direction[1] * primitive.length,
49 a[2] + primitive.direction[2] * primitive.length};
50 const std::array<double, 3> segment{b[0] - a[0], b[1] - a[1], b[2] - a[2]};
51 const std::array<double, 3> offset{originX - a[0], originY - a[1], originZ - a[2]};
52 const double rr = 1.0;
53 const double ss = segment[0] * segment[0] + segment[1] * segment[1] + segment[2] * segment[2];
54 const double rs = ray[0] * segment[0] + ray[1] * segment[1] + ray[2] * segment[2];
55 const double ro = ray[0] * offset[0] + ray[1] * offset[1] + ray[2] * offset[2];
56 const double so = segment[0] * offset[0] + segment[1] * offset[1] + segment[2] * offset[2];
57 const double denominator = rr * ss - rs * rs;
58 double rayT = denominator > 1e-12 ? (rs * so - ss * ro) / denominator : -ro;
59 double segmentT = denominator > 1e-12 ? (rr * so - rs * ro) / denominator : 0.0;
60 rayT = std::max(0.0, rayT);
61 segmentT = std::clamp(segmentT, 0.0, 1.0);
62 const double dx = originX + ray[0] * rayT - (a[0] + segment[0] * segmentT);
63 const double dy = originY + ray[1] * rayT - (a[1] + segment[1] * segmentT);
64 const double dz = originZ + ray[2] * rayT - (a[2] + segment[2] * segmentT);
65 const double distance = std::sqrt(dx * dx + dy * dy + dz * dz);
66 if (distance <= primitive.length * 0.12 && rayT < bestDistance) {
67 bestDistance = rayT;
68 best = primitive.id.substr(10);
69 }
70 }
71 if (best.empty())
73 "ray", {}, "procgen_editing.meshVertexAxisGizmo"));
74 return Result<std::string>::success(std::move(best));
75}
76
77} // namespace eve::procgen_editing
size_t offset
std::array< float, 3 > position
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
float dz
float dy
float dx
std::map< Cell, int > best
std::optional< InteractionSession > session
Definition Tactics.cpp:39
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
Stateful CPU sculpting session with explicit bake, restore, and undo semantics.
editing::GizmoSnapshot build(const procgen::MeshDeformationSession &session, double axisLength=1.0) const
Build three pickable axis arrows at the current selection center.
Result< std::string > pickAxisResult(const editing::GizmoSnapshot &snapshot, double originX, double originY, double originZ, double directionX, double directionY, double directionZ) const
Pick x, y, or z arrow using a normalized or non-normalized world ray.
Immutable revision-tagged overlay snapshot consumed by any viewport renderer.
std::vector< GizmoPrimitive > primitives
std::vector< Diagnostic > diagnostics