载入中...
搜索中...
未找到
StrandsDatas.cpp
浏览该文件的文档.
2
3#include "common/Diagnostic.h"
4
5#include <cmath>
6#include <limits>
7#include <string>
8
9#include <glm/glm.hpp>
10
11namespace eve::graphics::hair {
12namespace {
13
14bool finiteVec(const glm::vec3 &v) {
15 return std::isfinite(v.x) && std::isfinite(v.y) && std::isfinite(v.z);
16}
17
18} // namespace
19
20void StrandsDatas::setPoints(std::vector<StrandPoint> points) { points_ = std::move(points); }
21
22void StrandsDatas::setCurves(std::vector<StrandCurve> curves) { curves_ = std::move(curves); }
23
25 const auto index = static_cast<uint32_t>(points_.size());
26 points_.push_back(point);
27 return index;
28}
29
31 const auto index = static_cast<uint32_t>(curves_.size());
32 curves_.push_back(curve);
33 return index;
34}
35
37 points_.clear();
38 curves_.clear();
39}
40
42 if (curves_.empty()) {
44 DiagnosticCode::InvalidArgument, "StrandsDatas: no curves", "hair.strands.curves"));
45 }
46 if (points_.empty()) {
48 DiagnosticCode::InvalidArgument, "StrandsDatas: no points", "hair.strands.points"));
49 }
50 for (size_t ci = 0; ci < curves_.size(); ++ci) {
51 const StrandCurve &c = curves_[ci];
52 if (c.pointCount < 2u) {
54 DiagnosticCode::InvariantViolation, "StrandsDatas: curve needs at least 2 points",
55 "hair.strands.curves[" + std::to_string(ci) + "].pointCount"));
56 }
57 const uint64_t end = uint64_t(c.pointOffset) + uint64_t(c.pointCount);
58 if (end > points_.size()) {
60 DiagnosticCode::InvariantViolation, "StrandsDatas: curve range exceeds points",
61 "hair.strands.curves[" + std::to_string(ci) + "]"));
62 }
63 if (!std::isfinite(c.length) || c.length < 0.f) {
65 DiagnosticCode::InvalidArgument, "StrandsDatas: invalid curve length",
66 "hair.strands.curves[" + std::to_string(ci) + "].length"));
67 }
68 for (uint32_t pi = 0; pi < c.pointCount; ++pi) {
69 const StrandPoint &p = points_[c.pointOffset + pi];
70 if (!finiteVec(p.position) || !std::isfinite(p.radius) || p.radius < 0.f ||
71 !std::isfinite(p.u)) {
73 DiagnosticCode::InvalidArgument, "StrandsDatas: non-finite or negative point",
74 "hair.strands.points"));
75 }
76 }
77 }
78 return Result<void>::success();
79}
80
81std::span<const StrandPoint> StrandsDatas::curvePoints(size_t curveIndex) const {
82 if (curveIndex >= curves_.size()) return {};
83 const StrandCurve &c = curves_[curveIndex];
84 if (uint64_t(c.pointOffset) + uint64_t(c.pointCount) > points_.size()) return {};
85 return std::span<const StrandPoint>(points_.data() + c.pointOffset, c.pointCount);
86}
87
88void StrandsDatas::computeBounds(glm::vec3 &outMin, glm::vec3 &outMax) const {
89 if (points_.empty()) {
90 outMin = glm::vec3(0.f);
91 outMax = glm::vec3(0.f);
92 return;
93 }
94 outMin = glm::vec3(std::numeric_limits<float>::max());
95 outMax = glm::vec3(std::numeric_limits<float>::lowest());
96 for (const StrandPoint &p : points_) {
97 outMin = glm::min(outMin, p.position);
98 outMax = glm::max(outMax, p.position);
99 }
100}
101
102} // namespace eve::graphics::hair
glm::vec4 p[6]
Stable, structured diagnostics shared by engine modules.
float v
std::int32_t c
std::shared_ptr< const std::vector< glm::vec2 > > points
Heightmap curve
uint32_t index
glm::vec3 point
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
uint32_t addPoint(const StrandPoint &point)
Adds point.
std::span< const StrandCurve > curves() const
Borrowed curves; invalidated by mutation.
Result< void > validate() const
Verify offsets, counts, and finite values.
void setCurves(std::vector< StrandCurve > curves)
Sets the curves.
void setPoints(std::vector< StrandPoint > points)
Sets the points.
void computeBounds(glm::vec3 &outMin, glm::vec3 &outMax) const
Axis-aligned bounds of all points; empty → zero box at origin.
std::span< const StrandPoint > points() const
Borrowed points; invalidated by mutation.
uint32_t addCurve(const StrandCurve &curve)
Adds curve.
std::span< const StrandPoint > curvePoints(size_t curveIndex) const
Borrowed points of one curve.
Procedural hair/fur card meshes + material/LOD helpers (no strand simulation).
Definition Graphics.h:58
One strand as a contiguous point range. @ownership Value type owned by StrandsDatas.
One control point on a hair curve (UE FHairStrandsDatas point analogue). @ownership Value type owned ...