载入中...
搜索中...
未找到
ModelData.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Resource.h"
6#include "common/Result.h"
7
8#include "medialoader/model/ModelScene.h"
9
10#include <memory>
11#include <string>
12#include <string_view>
13
14struct aiMesh;
15struct aiScene;
16struct aiMaterial;
17
18namespace eve {
19namespace image {
20class ImageData;
21}
22namespace model3d {
23
25struct SurfaceUv {
26 float u = 0.f;
27 float v = 0.f;
28 float barycentricA = 0.f;
29 float barycentricB = 0.f;
30 float barycentricC = 0.f;
31 int triangleIndex = -1;
32 int uvChannel = 0;
33};
34
40public:
47 explicit ModelData(medialoader::ModelScene scene, std::string uri = "", bool uvFlipped = false);
49 bool hasFlippedUvs() const noexcept { return uvFlipped_; }
51 ~ModelData() override;
52
54 bool empty() const;
56 int getMeshCount() const;
58 int getMaterialCount() const;
61 int getVertexCount(int meshIndex) const;
64 int getFaceCount(int meshIndex) const;
66 float getVertexPosition(int meshIndex, int vertexIndex, int component) const;
70 float getVertexNormal(int meshIndex, int vertexIndex, int component) const;
85 [[nodiscard]] eve::Result<void> setVertexNormal(int meshIndex, int vertexIndex, float x, float y,
86 float z);
98 [[nodiscard]] eve::Result<void> applyVertexNormals(int meshIndex, std::string_view kind);
111 [[nodiscard]] eve::Result<void> applyVertexNormalsFrom(int meshIndex, std::string_view kind,
112 float originX, float originY, float originZ);
127 [[nodiscard]] eve::Result<std::unique_ptr<image::ImageData>> bakeNormalMap(
128 int meshIndex, int width, int height, int uvChannel = 0, std::string_view space = "tangent") const;
130 int getFaceVertexIndex(int meshIndex, int triangleIndex, int corner) const;
133 bool hasNormals(int meshIndex) const;
136 bool hasTexCoords(int meshIndex) const;
138 int getTexCoordChannelCount(int meshIndex) const;
140 bool hasTexCoordChannel(int meshIndex, int channel) const;
142 float getTexCoord(int meshIndex, int channel, int vertexIndex, int component) const;
155 [[nodiscard]] eve::Result<SurfaceUv> mapSurfacePointToUv(
156 int meshIndex, int triangleIndex, float localX, float localY, float localZ,
157 int channel = 0) const;
159 bool hasTangents(int meshIndex) const;
161 float getTangent(int meshIndex, int vertexIndex, int component) const;
163 float getBitangent(int meshIndex, int vertexIndex, int component) const;
165 int getVertexColorChannelCount(int meshIndex) const;
167 bool hasVertexColorChannel(int meshIndex, int channel) const;
169 float getVertexColor(int meshIndex, int channel, int vertexIndex, int component) const;
170
171 // ---- material accessors ----
173 int getMaterialIndex(int meshIndex) const;
175 std::string getMaterialName(int matIndex) const;
177 float getMaterialBaseColorR(int matIndex) const;
179 float getMaterialBaseColorG(int matIndex) const;
181 float getMaterialBaseColorB(int matIndex) const;
183 float getMaterialBaseColorA(int matIndex) const;
185 float getMaterialMetallicFactor(int matIndex) const;
187 float getMaterialRoughnessFactor(int matIndex) const;
189 float getMaterialOpacity(int matIndex) const;
191 bool getMaterialTwoSided(int matIndex) const;
193 std::string getMaterialAlphaMode(int matIndex) const;
195 float getMaterialAlphaCutoff(int matIndex) const;
196
202 int getMaterialTextureSlotCount(int matIndex, const std::string &type) const;
204 std::string getMaterialTexturePath(int matIndex, const std::string &type, int slot = 0) const;
206 int getMaterialTextureEmbeddedIndex(int matIndex, const std::string &type, int slot = 0) const;
207
208 // ---- embedded textures (glTF / FBX can embed PNG/JPEG blobs) ----
210 int getEmbeddedTextureCount() const;
212 std::string getEmbeddedTextureName(int idx) const;
214 int getEmbeddedTextureWidth(int idx) const;
216 int getEmbeddedTextureHeight(int idx) const;
223 image::ImageData *getEmbeddedTextureImageData(int idx) const;
224
226 int getMorphTargetCount(int meshIndex) const;
228 std::string getMorphTargetName(int meshIndex, int morphIndex) const;
229
231 bool hasBones(int meshIndex) const;
233 int getBoneCount(int meshIndex) const;
235 std::string getBoneName(int meshIndex, int boneIndex) const;
237 float getInverseBindMatrixElement(int meshIndex, int boneIndex, int elementIndex) const;
239 int getBoneWeightCount(int meshIndex, int boneIndex) const;
241 int getBoneWeightVertex(int meshIndex, int boneIndex, int weightIndex) const;
243 float getBoneWeightValue(int meshIndex, int boneIndex, int weightIndex) const;
244
246 int getAnimationCount() const;
248 std::string getAnimationName(int animIndex) const;
249
251 const aiScene *getScene() const;
253 const aiMesh *getMesh(int meshIndex) const;
254
256 void adopt(eve::Resource &replacement) override;
257
258private:
260 const aiMesh *meshAt(int meshIndex) const;
267 aiMesh *meshAtMutable(int meshIndex);
268 const aiMaterial *materialAt(int matIndex) const;
269
270 medialoader::ModelScene scene;
271 bool uvFlipped_ = false;
272};
273
274} // namespace model3d
275} // namespace eve
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
bool hasNormals
vk::UniqueImage image
std::uint32_t height
std::uint32_t width
TokenKind kind
int idx
std::string uri
std::weak_ptr< PrimitiveScene > scene
Move-only, checked operation results for the common layer.
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...
Definition Resource.h:51
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Represents raw pixel data.
Definition ImageData.h:38
CPU-side decoded 3D model (Assimp scene owned via medialoader::ModelScene). Does not upload to GPU — ...
Definition ModelData.h:39
~ModelData() override
Model data.
bool hasFlippedUvs() const noexcept
Whether the loader applied the UV-flip postprocess to this owned scene.
Definition ModelData.h:49
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
Owning result of mapping a triangle-local surface point to one UV channel.
Definition ModelData.h:25