#pragma once #include #include #include #include #include #include #include #include #include #include #include "vk_materials.h" #include "asset_locator.h" class VulkanEngine; class MeshAsset; class AssetManager { public: struct MaterialOptions { std::string albedoPath; std::string metalRoughPath; bool albedoSRGB = true; bool metalRoughSRGB = false; GLTFMetallic_Roughness::MaterialConstants constants{}; MaterialPass pass = MaterialPass::MainColor; }; struct MeshGeometryDesc { enum class Type { Provided, Cube, Sphere }; Type type = Type::Provided; std::span vertices{}; std::span indices{}; int sectors = 16; int stacks = 16; }; struct MeshMaterialDesc { enum class Kind { Default, Textured }; Kind kind = Kind::Default; MaterialOptions options{}; }; struct MeshCreateInfo { std::string name; MeshGeometryDesc geometry; MeshMaterialDesc material; }; void init(VulkanEngine *engine); void cleanup(); std::string shaderPath(std::string_view name) const; std::string modelPath(std::string_view name) const; std::string assetPath(std::string_view name) const; std::optional > loadGLTF(std::string_view nameOrPath); std::shared_ptr createMesh(const MeshCreateInfo &info); std::shared_ptr getPrimitive(std::string_view name) const; std::shared_ptr createMesh(const std::string &name, std::span vertices, std::span indices, std::shared_ptr material = {}); std::shared_ptr getMesh(const std::string &name) const; bool removeMesh(const std::string &name); const AssetPaths &paths() const { return _locator.paths(); } void setPaths(const AssetPaths &p) { _locator.setPaths(p); } private: VulkanEngine *_engine = nullptr; AssetLocator _locator; std::unordered_map > _gltfCacheByPath; std::unordered_map > _meshCache; std::unordered_map _meshMaterialBuffers; std::unordered_map > _meshOwnedImages; AllocatedBuffer createMaterialBufferWithConstants(const GLTFMetallic_Roughness::MaterialConstants &constants) const; std::shared_ptr createMaterial(MaterialPass pass, const GLTFMetallic_Roughness::MaterialResources &res) const; std::pair loadImageFromAsset(std::string_view path, bool srgb) const; };