载入中...
搜索中...
未找到
GroomAsset.cpp
浏览该文件的文档.
2
3#include "common/Diagnostic.h"
4
5#include <string>
6
7namespace eve::graphics::hair {
8
10 if (group.name.empty()) {
12 DiagnosticCode::InvalidArgument, "GroomAsset::addGroup: empty name",
13 "hair.groom.group.name"));
14 }
15 for (const GroomGroup &existing : groups_) {
16 if (existing.groupId == group.groupId) {
18 DiagnosticCode::AlreadyExists, "GroomAsset::addGroup: duplicate groupId",
19 "hair.groom.group.id"));
20 }
21 }
22 if (group.lods.empty()) {
24 lod.screenSize = 1.f;
25 lod.representation = Representation::Strands;
26 lod.curveFraction = 1.f;
27 lod.thicknessScale = 1.f;
28 group.lods.push_back(lod);
29 }
30 auto strandsOk = group.strands.validate();
31 if (!strandsOk.ok()) return Result<void>::failure(strandsOk.status());
32 if (group.guides.curveCount() > 0) {
33 auto guidesOk = group.guides.validate();
34 if (!guidesOk.ok()) return Result<void>::failure(guidesOk.status());
35 }
36 groups_.push_back(std::move(group));
37 return Result<void>::success();
38}
39
40const GroomGroup *GroomAsset::groupAt(size_t index) const {
41 if (index >= groups_.size()) return nullptr;
42 return &groups_[index];
43}
44
45const GroomGroup *GroomAsset::findGroupById(uint32_t groupId) const {
46 for (const GroomGroup &g : groups_) {
47 if (g.groupId == groupId) return &g;
48 }
49 return nullptr;
50}
51
52void GroomAsset::clear() { groups_.clear(); }
53
55 if (groups_.empty()) {
57 DiagnosticCode::InvalidArgument, "GroomAsset: no groups", "hair.groom.groups"));
58 }
59 for (size_t i = 0; i < groups_.size(); ++i) {
60 auto ok = groups_[i].strands.validate();
61 if (!ok.ok()) return Result<void>::failure(ok.status());
62 if (groups_[i].guides.curveCount() > 0) {
63 auto guidesOk = groups_[i].guides.validate();
64 if (!guidesOk.ok()) return Result<void>::failure(guidesOk.status());
65 }
66 if (groups_[i].lods.empty()) {
68 DiagnosticCode::InvariantViolation, "GroomAsset: group has empty LOD table",
69 "hair.groom.groups[" + std::to_string(i) + "].lods"));
70 }
71 }
72 return Result<void>::success();
73}
74
75size_t selectLodIndex(const std::vector<GroomLod> &lods, float screenSize) {
76 if (lods.empty()) return 0;
77 // Ordered finest → coarsest. Pick the last entry whose threshold is still
78 // >= the current screen size (i.e. the coarsest LOD that still applies).
79 size_t best = 0;
80 for (size_t i = 0; i < lods.size(); ++i) {
81 if (screenSize <= lods[i].screenSize) best = i;
82 }
83 return best;
84}
85
86} // namespace eve::graphics::hair
building::EdgeCurveGroup group
Stable, structured diagnostics shared by engine modules.
tensor::Graph g
Definition GpuGraph.cpp:7
int lod
std::map< Cell, int > best
uint32_t index
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
const GroomGroup * groupAt(size_t index) const
const GroomGroup * findGroupById(uint32_t groupId) const
Result< void > validate() const
Validate every group strands buffer and LOD table.
Result< void > addGroup(GroomGroup group)
Append a group; fails when name is empty or groupId collides. @ownership group is moved into the asse...
Definition GroomAsset.cpp:9
Procedural hair/fur card meshes + material/LOD helpers (no strand simulation).
Definition Graphics.h:58
size_t selectLodIndex(const std::vector< GroomLod > &lods, float screenSize)
Pick the LOD index for a given screen size (largest screenSize ≤ query).
One groom group (UE hair group analogue: bangs / scalp / beard …). @ownership Owned by GroomAsset.
Definition GroomAsset.h:31
One LOD entry for a groom group.
Definition GroomAsset.h:17
float screenSize
Switch to this LOD when screen size falls below this value (0..1).
Definition GroomAsset.h:19