载入中...
搜索中...
未找到
TerrainDetailCard.cpp
浏览该文件的文档.
2
3#include <new>
4
5namespace eve::asset_procgen {
6namespace {
7
8void appendQuad(TerrainDetailCardGeometry& geometry, float xx, float xz, float normalX, float normalZ) {
9 const std::uint32_t base = static_cast<std::uint32_t>(geometry.positions.size() / 3);
10 geometry.positions.insert(geometry.positions.end(), {-0.5f * xx, 0.f, -0.5f * xz, 0.5f * xx, 0.f, 0.5f * xz,
11 0.5f * xx, 1.f, 0.5f * xz, -0.5f * xx, 1.f, -0.5f * xz});
12 for (int vertex = 0; vertex < 4; ++vertex) geometry.normals.insert(geometry.normals.end(), {normalX, 0.f, normalZ});
13 geometry.texcoords.insert(geometry.texcoords.end(), {0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f});
14 geometry.indices.insert(geometry.indices.end(), {base, base + 2, base + 1, base, base + 3, base + 2});
15}
16
17} // namespace
18
20 if (prototype.prototype.empty())
22 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain Detail prototype identity is empty", {}, {},
23 "asset.procgen.terrainDetailCard"));
24 if (prototype.usePrototypeMesh || prototype.renderMode == "VertexLit")
26 Diagnostic::error(DiagnosticCode::Unsupported, "mesh-backed terrain Detail requires its authored mesh",
27 prototype.prototype, {}, "asset.procgen.terrainDetailCard"));
28 if (!prototype.prototype.starts_with("unity-texture-guid:"))
30 Diagnostic::error(DiagnosticCode::InvalidArgument, "texture terrain Detail identity is invalid",
31 prototype.prototype, {}, "asset.procgen.terrainDetailCard"));
32 try {
34 if (prototype.renderMode == "GrassBillboard") {
35 geometry.cameraFacing = true;
36 appendQuad(geometry, 1.f, 0.f, 0.f, 1.f);
37 } else if (prototype.renderMode == "Grass") {
38 appendQuad(geometry, 1.f, 0.f, 0.f, 1.f);
39 appendQuad(geometry, 0.f, 1.f, 1.f, 0.f);
40 } else {
42 Diagnostic::error(DiagnosticCode::Unsupported, "terrain Detail render mode has no card representation",
43 prototype.renderMode, {}, "asset.procgen.terrainDetailCard"));
44 }
45 return Result<TerrainDetailCardGeometry>::success(std::move(geometry));
46 } catch (const std::bad_alloc&) {
48 Diagnostic::error(DiagnosticCode::Failed, "terrain Detail card allocation failed", prototype.prototype, {},
49 "asset.procgen.terrainDetailCard"));
50 }
51}
52
53} // namespace eve::asset_procgen
Canonical card geometry for texture-backed Unity terrain details.
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
Result< TerrainDetailCardGeometry > buildTerrainDetailCard(const RuntimeInstancePrototype &prototype)
Build bottom-anchored unit cards for a texture-backed terrain Detail prototype.
Runtime vegetation prototype metadata retained from the source terrain.
Owning unit geometry whose instance transform supplies Unity's exact width and height.