载入中...
搜索中...
未找到
VegetationPacking.cpp
浏览该文件的文档.
2#include <cmath>
3#include <new>
5
6namespace eve::graphics {
7namespace {
8bool finite(glm::vec3 value) { return std::isfinite(value.x) && std::isfinite(value.y) && std::isfinite(value.z); }
9bool finite(glm::vec4 value) { return finite(glm::vec3(value)) && std::isfinite(value.w); }
10bool packed(float value) {
11 return std::isfinite(value) && value >= 0 && value <= 4194303.f && value == std::floor(value);
12}
13glm::vec2 unpack(float value) { return {std::floor(value / 2048.f) / 2047.f, std::fmod(value, 2048.f) / 2047.f}; }
14} // namespace
16 if (vertices.size() > 4 * 1024 * 1024)
18 Diagnostic::error(DiagnosticCode::InvalidArgument, "vegetation vertex budget exceeded"));
19 for (const auto& v : vertices) {
20 bool masks = true;
21 for (int c = 0; c < 4; ++c) masks = masks && v.color[c] >= 0 && v.color[c] <= 1;
22 if (!finite(v.position) || !finite(v.normal) || !finite(v.color) || !finite(v.texcoord0) ||
23 !finite(v.texcoord1) || !finite(v.texcoord3) || !packed(v.texcoord0.z) || !packed(v.texcoord0.w) || !masks)
25 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid TVE vertex attribute or packed pair", {},
26 {}, "graphics.vegetation.packing"));
27 }
28 try {
29 std::vector<VegetationVertex> result;
30 result.reserve(vertices.size());
31 for (const auto& source : vertices) {
33 v.position = source.position;
34 v.normal = source.normal;
35 v.variation = source.color.r;
36 v.occlusion = source.color.g;
37 v.detail = source.color.b;
38 v.bending = source.color.a;
39 const auto motion = unpack(source.texcoord0.z), bounds = unpack(source.texcoord0.w) * 100.f;
40 v.branch = motion.x;
41 v.flutter = motion.y;
42 v.boundsHeight = bounds.x;
43 v.boundsRadius = bounds.y;
44 v.texcoord = glm::vec2(source.texcoord0);
45 v.secondaryTexcoord = glm::vec2(source.texcoord1);
46 v.detailCoord = {source.texcoord1.z, source.texcoord1.w};
47 v.pivot = {source.texcoord3.x, source.texcoord3.z, source.texcoord3.y};
48 result.push_back(v);
49 }
50 return Result<std::vector<VegetationVertex>>::success(std::move(result));
51 } catch (const std::bad_alloc&) {
53 Diagnostic::error(DiagnosticCode::Failed, "vegetation unpack allocation failed"));
54 }
55}
56} // namespace eve::graphics
double value
float v
std::int32_t c
bool finite
std::vector< Point > vertices
const UnitySourceAsset & source
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
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Result< std::vector< VegetationVertex > > decodeTveVegetationVertices(std::span< const TvePackedVertex > vertices)
Decode TVE 12.x color/motion/bounds/detail/pivot packing to native rest vertices. Borrows input only ...
Owning rest vertex in object space, with unpacked authoring channels. Bending/branch/flutter/variatio...
glm::vec4 bounds