Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
ModelAssetPipeline.h
1#pragma once
2#include <filesystem>
3#include <future>
4#include <memory>
5#include <vector>
6
7#include "Engine/Ecs/EcsData.h"
8
9class NamedThreadPool;
10
11namespace Engine::Assets
12{
15 class MeshAssetManager;
16 class Model;
17 class ModelAssetManager;
18 class SkinAssetManager;
20} // namespace Engine::Assets
21
22namespace Engine::Core
23{
24 class AssetManager;
25 class RenderingDataManager;
26}
27
29{
30 class GltfLoader;
31}
32
33namespace Engine::Ecs
34{
36
42 friend class AssetManager;
43 friend class Engine;
44
45 public:
58 Assets::MeshAssetManager * meshAssetManager,
59 Assets::MaterialAssetManager * materialAssetManager,
60 Assets::ModelAssetManager * modelAssetManager,
61 Assets::SkinAssetManager * skinAssetManager,
62 Assets::AnimationAssetManager * animationAssetManager,
63 Assets::TextureAssetManager * textureAssetManager,
64 NamedThreadPool * assetLoaderPool,
65 Core::AssetManager * assetManager = nullptr
66 );
67
72
77 void submitAsset(const std::filesystem::path &asset);
78
83 void tick(bool async = true);
84
89 void setRenderingDataManager( Core::RenderingDataManager * renderingDataManager) { renderingDataManager_ = renderingDataManager; }
90
96
103 std::vector<CompletedMeshletGeneration> takePendingMeshletCompletions();
104
110 [[nodiscard]] bool hasPendingWork() const {
111 return
112 !assetQueue_.empty() ||
113 !modelLoadingFutures_.empty() ||
114 !materialResults_.empty() ||
115 !primitiveDataFutures_.empty() ||
116 !meshletGenerationFutures_.empty() ||
118 !pendingKtx2Futures_.empty();
119 }
120
125
126 private:
127 void submitLoadModel(bool async = true);
128 void processModel(bool async = true);
129 void processSkinData(bool async = true);
130 void processMaterial(bool async = true);
131 void processMeshData(bool async = true);
132 void processKtx2Textures(bool async = true);
133
144 void processTextures(Assets::Model* modelAsset,
145 const std::shared_ptr<tinygltf::Model>& gltfModel,
146 const std::filesystem::path& modelPath);
147
150 Assets::ModelAssetManager * modelAssetManager_ = nullptr;
154 Core::RenderingDataManager * renderingDataManager_ = nullptr;
157
158 NamedThreadPool * threadPool_ = nullptr;
160
161 std::vector<std::filesystem::path> assetQueue_;
162 std::vector<GltfModelFuture> modelLoadingFutures_;
163 std::vector<MaterialLoadingData> materialResults_;
164 std::vector<std::future<PrimitiveDataLoading>> primitiveDataFutures_;
165 std::vector<std::future<CompletedMeshletGeneration>> meshletGenerationFutures_;
166
167 // Queue for completed meshlet generations waiting to be written to registry
168 std::vector<CompletedMeshletGeneration> pendingMeshletCompletions_;
169
170 // KTX2 texture loads submitted to thread pool, polled each tick()
171 std::vector<Ktx2LoadFuture> pendingKtx2Futures_;
172
173 NamedThreadPool* assetLoaderPool_ = nullptr;
174 };
175
176} // namespace Engine::Ecs
Stores animation clips keyed by their source mesh path.
Loads glTF files and converts tinygltf data into engine asset data.
Definition GltfLoader.h:39
Asset manager for materials keyed by source file path and material name.
Stores mesh data with their primitives.
Definition MeshAsset.h:51
Stores skin and skeleton binding data keyed by source mesh path.
Definition SkinAsset.h:93
Asset manager for texture assets keyed by filesystem path.
Coordinates engine asset loading pipelines and runtime texture descriptor ownership.
Master asset import pipeline that dispatches asset submissions to the texture, model and audio sub-pi...
void submitAsset(const std::filesystem::path &asset)
Requests the load of a gltf file.
ModelAssetPipeline(Assets::MeshAssetManager *meshAssetManager, Assets::MaterialAssetManager *materialAssetManager, Assets::ModelAssetManager *modelAssetManager, Assets::SkinAssetManager *skinAssetManager, Assets::AnimationAssetManager *animationAssetManager, Assets::TextureAssetManager *textureAssetManager, NamedThreadPool *assetLoaderPool, Core::AssetManager *assetManager=nullptr)
Create a model asset loading pipeline.
void submitLoadModel(bool async=true)
void processKtx2Textures(bool async=true)
Assets::Loaders::GltfLoader * loader_
Assets::ModelAssetManager * modelAssetManager_
std::vector< std::future< CompletedMeshletGeneration > > meshletGenerationFutures_
void tick(bool async=true)
Advances all stages of the model loading pipeline.
~ModelAssetPipeline()
Destroy the pipeline and its owned glTF loader resources.
AssetImportPipeline * assetImportPipeline_
For async lightmap loading.
Assets::MeshAssetManager * meshAssetManager_
std::vector< std::filesystem::path > assetQueue_
std::vector< GltfModelFuture > modelLoadingFutures_
bool hasPendingWork() const
Check if the pipeline still has in-flight work (loading, meshlet generation, etc.) Used to defer buff...
void processMaterial(bool async=true)
std::vector< MaterialLoadingData > materialResults_
std::vector< CompletedMeshletGeneration > pendingMeshletCompletions_
void processMeshData(bool async=true)
Assets::SkinAssetManager * skinAssetManager_
void processSkinData(bool async=true)
void processTextures(Assets::Model *modelAsset, const std::shared_ptr< tinygltf::Model > &gltfModel, const std::filesystem::path &modelPath)
Extracts and registers texture assets from loaded glTF models.
Assets::TextureAssetManager * textureAssetManager_
std::vector< CompletedMeshletGeneration > takePendingMeshletCompletions()
Get and clear pending meshlet completions. Call this at a safe point to retrieve completed meshlet ge...
Assets::AnimationAssetManager * animationAssetManager_
std::vector< Ktx2LoadFuture > pendingKtx2Futures_
std::vector< std::future< PrimitiveDataLoading > > primitiveDataFutures_
Assets::MaterialAssetManager * materialAssetManager_
void setRenderingDataManager(Core::RenderingDataManager *renderingDataManager)
Sets the RenderingDataManager to notify when meshes/materials are loaded.
void discardPendingWork()
Clears all queued and in-flight model loading work.
void setAssetImportPipeline(AssetImportPipeline *pipeline)
Sets the master AssetImportPipeline for async lightmap loading.
Core::AssetManager * assetManager_
For TextureHandleRegistry access.
void processModel(bool async=true)
Core::RenderingDataManager * renderingDataManager_
EnTT component data used by engine systems.