载入中...
搜索中...
未找到
Mesh.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Result.h"
6#include "graphics/Drawable.h"
7
8#include <array>
9#include <cstdint>
10#include <map>
11#include <span>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16struct aiMesh;
17
18namespace eve::graphics {
19
27public:
28 int indexCount = 0;
29 void *gpuHandle = nullptr; // vulkan::GpuMesh*
31 int gpuVertexCount = 0;
33 bool hasGpuSkinning() const noexcept { return gpuSkinned_; }
35 int getSkinPaletteCount() const noexcept { return static_cast<int>(skinPalette_.size() / 16u); }
40 [[nodiscard]] Result<void> setSkinPalette(const float* matrices, int matrixCount);
42 const std::vector<float> &skinPalette() const noexcept { return skinPalette_; }
44 void markGpuSkinned(bool value) noexcept { gpuSkinned_ = value; }
45
49 [[nodiscard]] Result<void> setTexcoordSet(uint32_t set, std::span<const float> values);
51 std::span<const float> texcoordSet(uint32_t set) const;
53 uint64_t texcoordRevision() const { return texcoordRevision_; }
60 float boundsCx = 0.f;
61 float boundsCy = 0.f;
62 float boundsCz = 0.f;
63 float boundsRadius = 0.f;
64
66 bool hasBounds() const { return boundsRadius > 0.f; }
67
73 [[nodiscard]] Result<std::array<float, 6>> localBounds() const;
74
76 void computeBounds(const float *posXYZ, int vertexCount);
77
79 uint64_t geometryGeneration() const { return geometryGeneration_; }
80
81private:
82 uint64_t geometryGeneration_ = 0;
83 std::array<float, 6> localBounds_{};
84 bool hasLocalBounds_ = false;
85
86public:
88 void draw(Graphics* /*gfx*/, const glm::mat4& /*matrix*/) const override {}
94 void drawOcclusion(Graphics* gfx, const glm::mat4& matrix) const override;
95
96 // ---- morph targets (CPU) ----
98 void clearMorphData();
100 void initMorphBase(int vertexCount, const float *posXYZ, const float *nrmXYZ = nullptr,
101 const float *uvST = nullptr);
104 bool addMorphTarget(const std::string &name, const float *deltaPosXYZ);
106 bool addMorphTargetAbsolute(const std::string &name, const float *absPosXYZ);
112 [[nodiscard]] Result<void> setMorphNormalDeltas(std::string_view name, std::span<const float> deltas);
113
115 int getVertexCount() const;
117 int getMorphCount() const;
119 std::string getMorphName(int index) const;
121 bool hasMorph(const std::string &name) const;
123 bool setMorphWeight(const std::string &name, float weight);
125 float getMorphWeight(const std::string &name) const;
127 void clearMorphWeights();
129 bool isMorphDirty() const { return morphDirty_; }
131 void markMorphClean() { morphDirty_ = false; }
133 bool hasMorphData() const { return !basePos_.empty(); }
134
136 void computeMorphedPositions(std::vector<float> &outPos, std::vector<float> &outNrm) const;
137
139 const std::vector<float> &baseUv() const { return baseUv_; }
140
142 void captureImportedAttributes(const ::aiMesh &mesh);
153 [[nodiscard]] Result<void> setTangentFrame(std::span<const float> tangents, std::span<const float> bitangents);
160 [[nodiscard]] Result<void> validateTangentFrame(std::span<const float> tangents,
161 std::span<const float> bitangents) const;
170 [[nodiscard]] Result<void> adoptTangentFrame(std::vector<float> &&tangents, std::vector<float> &&bitangents);
179 [[nodiscard]] Result<void> validateMotionHighlights(std::span<const float> values) const;
188 [[nodiscard]] Result<void> adoptMotionHighlights(std::vector<float> &&values);
195 [[nodiscard]] std::span<const float> motionHighlights() const { return motionHighlights_; }
203 [[nodiscard]] Result<void> validateVegetationFactors(std::span<const float> values) const;
212 [[nodiscard]] Result<void> adoptVegetationFactors(std::vector<float> &&values);
214 [[nodiscard]] std::span<const float> vegetationFactors() const { return vegetationFactors_; }
224 [[nodiscard]] Result<void> validateVegetationDeformationFactors(std::span<const float> values) const;
231 [[nodiscard]] Result<void> adoptVegetationDeformationFactors(std::vector<float> &&values);
233 [[nodiscard]] std::span<const float> vegetationDeformationFactors() const { return vegetationDeformationFactors_; }
234 int getUvChannelCount() const { return static_cast<int>(importedUvs_.size()); }
236 int getColorChannelCount() const { return static_cast<int>(importedColors_.size()); }
238 bool hasImportedTangents() const { return !importedTangents_.empty(); }
241 [[nodiscard]] uint64_t tangentFrameRevision() const { return tangentFrameRevision_; }
243 const std::vector<float> &importedUv(int channel) const;
245 const std::vector<float> &importedColor(int channel) const;
247 const std::vector<float> &importedTangents() const { return importedTangents_; }
249 const std::vector<float> &importedBitangents() const { return importedBitangents_; }
250
251private:
252 void markTangentFrameChanged() {
253 if (tangentFrameRevision_) ++tangentFrameRevision_;
254 }
255 std::map<uint32_t, std::vector<float>> texcoords_;
256 uint64_t texcoordRevision_ = 0;
257
258 struct MorphTarget {
259 std::string name;
260 std::vector<float> deltaPos; // xyz packed, size = vertexCount*3
261 std::vector<float> deltaNrm; // optional authored normal deltas
262 };
263
264 std::vector<float> basePos_;
265 std::vector<float> baseNrm_;
266 std::vector<float> baseUv_;
267 std::vector<MorphTarget> morphs_;
268 std::unordered_map<std::string, float> morphWeights_;
269 bool morphDirty_ = false;
270 std::vector<std::vector<float>> importedUvs_; // xy packed per channel
271 std::vector<std::vector<float>> importedColors_; // rgba packed per channel
272 std::vector<float> importedTangents_; // xyz packed
273 std::vector<float> importedBitangents_; // xyz packed
274 std::vector<float> motionHighlights_;
275 std::vector<float> vegetationFactors_;
276 std::vector<float> vegetationDeformationFactors_;
277 bool gpuSkinned_ = false;
278 std::vector<float> skinPalette_;
279 uint64_t tangentFrameRevision_ = 1;
280};
281
282} // namespace eve::graphics
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_BACKENDS
Definition Export.h:108
std::uint32_t vertexCount
std::uint32_t indexCount
OceanMeshSettings mesh
std::set< std::string > values
Object::Ptr value
Move-only, checked operation results for the common layer.
glm::dmat4 matrix
double weight
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Drawable base (textures, meshes, canvases).
Definition Drawable.h:18
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:26
bool hasMorphData() const
True when morph data.
Definition Mesh.h:133
bool isMorphDirty() const
True when morph dirty.
Definition Mesh.h:129
uint64_t geometryGeneration() const
Native upload generation; changes on each position upload, owner thread only.
Definition Mesh.h:79
const std::vector< float > & importedTangents() const
Imported tangents.
Definition Mesh.h:247
void markGpuSkinned(bool value) noexcept
Mark whether the backend vertex stream contains skin attributes.
Definition Mesh.h:44
int getUvChannelCount() const
Definition Mesh.h:234
int getColorChannelCount() const
Returns the color channel count.
Definition Mesh.h:236
uint64_t tangentFrameRevision() const
Tangent-frame mutation identity; zero disables revision caching after exhaustion. @thread Render thre...
Definition Mesh.h:241
std::span< const float > motionHighlights() const
Borrow motion-highlight scalars until replacement or mesh destruction.
Definition Mesh.h:195
uint64_t texcoordRevision() const
Revision used to invalidate backend UV uploads after a channel changes.
Definition Mesh.h:53
const std::vector< float > & baseUv() const
Base uv.
Definition Mesh.h:139
int getSkinPaletteCount() const noexcept
Number of matrices in the current skinning palette.
Definition Mesh.h:35
void draw(Graphics *, const glm::mat4 &) const override
Draws .
Definition Mesh.h:88
std::span< const float > vegetationDeformationFactors() const
Borrow TVE rest-deformation data until mesh mutation or destruction.
Definition Mesh.h:233
bool hasBounds() const
True when a valid bounding sphere is available for culling.
Definition Mesh.h:66
bool hasGpuSkinning() const noexcept
True after joint and weight data has been uploaded for GPU skinning.
Definition Mesh.h:33
std::span< const float > vegetationFactors() const
Borrow interleaved variation/occlusion pairs until mesh mutation or destruction.
Definition Mesh.h:214
bool hasImportedTangents() const
True when imported tangents.
Definition Mesh.h:238
const std::vector< float > & skinPalette() const noexcept
Packed column-major matrix palette used by graphics backends.
Definition Mesh.h:42
void markMorphClean()
Mark morph clean.
Definition Mesh.h:131
const std::vector< float > & importedBitangents() const
Imported bitangents.
Definition Mesh.h:249
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25