RavEngine
Loading...
Searching...
No Matches
MeshAsset.hpp
1#pragma once
2
3#include "mathtypes.hpp"
4#include "Ref.hpp"
5#include "Common3D.hpp"
6#include "Manager.hpp"
7#include "Filesystem.hpp"
8#include "Debug.hpp"
9#include <span>
10#if !RVE_SERVER
11 #include <RGL/Types.hpp>
12#endif
13#include "MeshAllocation.hpp"
14#include "Mesh.hpp"
15#include "MaterialShared.hpp"
16
17struct aiMesh;
18struct aiScene;
19
20namespace RavEngine{
21
23 bool keepInSystemRAM = false;
24 bool uploadToGPU = true;
25};
26
27class MeshAsset {
28public:
29
30 MeshAsset(const MeshAsset&) = delete;
31 MeshAsset(MeshAsset&&) = delete;
32
33 auto GetAttributes() const {
34 return attributes;
35 }
36
37protected:
38 MeshAsset() {}; // SkinnedMesh needs this
39
40 size_t totalVerts = 0, totalIndices = 0;
41 Bounds bounds;
42 float radius = 0;
43 MeshAttributes attributes;
44
45 friend class RenderEngine;
46#if !RVE_SERVER
47 MeshRange meshAllocation;
48#endif
49
55
60 void InitializeFromRawMesh(const MeshPart& mp, const MeshAssetOptions& options = MeshAssetOptions());
61 void InitializeFromRawMeshView(const MeshPartView& mp, const MeshAssetOptions& options = MeshAssetOptions());
62
63 // optionally stores a copy of the mesh in system memory
64 MeshPart systemRAMcopy;
65
66 MeshPart DeserializeMesh(const std::istream& stream);
67 std::pair<MeshPart,uint32_t> DeserializeMeshFromMemory(const std::span<uint8_t> mem);
68
69 friend class RenderEngine;
70
71public:
72
73 auto GetRadius() const {
74 return radius;
75 }
76#if !RVE_SERVER
77 auto GetAllocation() const {
78 return meshAllocation;
79 }
80#endif
81
82 struct Manager : public GenericWeakReadThroughCache<std::string,MeshAsset>{};
83
90 MeshAsset(const std::string& path, const MeshAssetOptions& options = MeshAssetOptions());
91
92 MeshAsset(const Filesystem::Path& pathOnDisk, const MeshAssetOptions& options = MeshAssetOptions());
93
102
107 MeshAsset(const MeshPart& mesh, const MeshAssetOptions& options = MeshAssetOptions()){
108 InitializeFromRawMesh(mesh, options);
109 }
110
111 MeshAsset(const MeshPartView& mesh, const MeshAssetOptions& options = MeshAssetOptions()){
112 InitializeFromRawMeshView(mesh,options);
113 }
114
115 constexpr inline const decltype(bounds)& GetBounds() const{
116 return bounds;
117 }
118
119 virtual ~MeshAsset();
120
121 constexpr inline const decltype(totalVerts) GetNumVerts() const {
122 return totalVerts;
123 }
124
125 constexpr inline const decltype(totalIndices) GetNumIndices() const {
126 return totalIndices;
127 }
128
129 constexpr inline decltype(systemRAMcopy)& GetSystemCopy(){
130 return systemRAMcopy;
131 }
132
133 inline bool hasSystemRAMCopy() const{
134 return systemRAMcopy.positions.size() > 0;
135 }
136
141 inline void DeallocSystemCopy(){
142 systemRAMcopy = MeshPart{};
143 }
144};
145
146}
Definition MeshAsset.hpp:27
MeshAsset(const std::string &path, const MeshAssetOptions &options=MeshAssetOptions())
void InitializeFromMeshPartFragments(const RavEngine::Vector< MeshPart > &mp, const MeshAssetOptions &options=MeshAssetOptions())
Definition MeshAsset.cpp:106
MeshAsset(const MeshPart &mesh, const MeshAssetOptions &options=MeshAssetOptions())
Definition MeshAsset.hpp:107
void DeallocSystemCopy()
Definition MeshAsset.hpp:141
MeshAsset(const RavEngine::Vector< MeshPart > &rawMeshData, const MeshAssetOptions &options=MeshAssetOptions())
Definition MeshAsset.hpp:99
void InitializeFromRawMesh(const MeshPart &mp, const MeshAssetOptions &options=MeshAssetOptions())
Definition MeshAsset.cpp:147
Definition RenderEngine.hpp:64
Definition concurrentqueue.h:747
Definition Animation.hpp:6
Definition mathtypes.hpp:122
Definition MeshAsset.hpp:22
Definition MeshAsset.hpp:82
Definition MaterialShared.hpp:9
Definition Mesh.hpp:70
Definition Mesh.hpp:53
Definition MeshAllocation.hpp:9