Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
AssetLoaders.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4
9#include <Common/Assert.hpp>
10#include <Common/Types.hpp>
14#include <ECS/Registry.hpp>
15#include <Utils/AssetUtils.hpp>
16
18
19class ShaderLoader : public AssetLoader<Shader> {
20 public:
21 ShaderLoader(std::filesystem::path path, Shader::Type type) : path(std::move(path)), type(type) {}
22
23 Shader operator()() override { return Shader(path, type); }
24
25 std::filesystem::path path;
27};
28
29class MaterialLoader : public AssetLoader<Material> {
30 public:
33 std::get<AssetRef<Texture>>(mat.albedoTexture).reset();
34 std::get<AssetRef<Texture>>(mat.normalTexture).reset();
35 std::get<AssetRef<Texture>>(mat.roughnessTexture).reset();
36 std::get<AssetRef<Texture>>(mat.metallicTexture).reset();
37 std::get<AssetRef<Texture>>(mat.emissiveTexture).reset();
38 }
39
52
54
55 private:
57 if (const auto& assetHandleOpt = std::get<OptionalAssetHandle>(mat.*textureMember)) {
60 std::get<AssetRef<Texture>>(mat.*textureMember) = read(textureAssetComponent);
61 }
62 }
63 }
64
66};
67
68class CubeMapLoader : public AssetLoader<CubeMap> {
69 public:
70 using Faces = std::array<HandleAndAsset<Image>, 6>;
71
75
76 CubeMap operator()() override {
78 out.loadFaces(_registry, faces[0], faces[1], faces[2], faces[3], faces[4], faces[5]);
79 return out;
80 }
81
83
84 private:
86 for (auto& f : faces) {
87 std::get<AssetRef<Image>>(f).reset();
88 }
89 }
90
92};
93
94} // namespace shkyera::utils::assets
Definition AssetLoader.hpp:6
Definition CubeMap.hpp:12
Definition Registry.hpp:28
bool hasComponent(Entity entity) const
Definition Registry.hpp:117
Component & getComponent(Entity entity)
Definition Registry.hpp:141
Definition Shader.hpp:8
Type
Definition Shader.hpp:10
Definition AssetLoaders.hpp:68
void resetInternalReferences()
Definition AssetLoaders.hpp:85
Registry * _registry
Definition AssetLoaders.hpp:91
CubeMapLoader(Registry *registry, Faces faces_)
Definition AssetLoaders.hpp:72
std::array< HandleAndAsset< Image >, 6 > Faces
Definition AssetLoaders.hpp:70
Faces faces
Definition AssetLoaders.hpp:82
CubeMap operator()() override
Definition AssetLoaders.hpp:76
Definition AssetLoaders.hpp:29
void constructTextureMember(Material &mat, auto textureMember)
Definition AssetLoaders.hpp:56
Material operator()() override
Definition AssetLoaders.hpp:40
Registry * _registry
Definition AssetLoaders.hpp:65
MaterialLoader(Registry *registry, Material mat_)
Definition AssetLoaders.hpp:31
Material mat
Definition AssetLoaders.hpp:53
Definition AssetLoaders.hpp:19
Shader::Type type
Definition AssetLoaders.hpp:26
std::filesystem::path path
Definition AssetLoaders.hpp:25
Shader operator()() override
Definition AssetLoaders.hpp:23
ShaderLoader(std::filesystem::path path, Shader::Type type)
Definition AssetLoaders.hpp:21
Definition AssetLoaders.hpp:17
AssetRef< AssetType > read(AssetComponent< AssetType > &assetComponent)
Definition AssetUtils.hpp:81
Definition Mesh.cpp:16
Definition Clock.hpp:9
Definition Material.hpp:10
HandleAndAsset< Texture > roughnessTexture
Definition Material.hpp:23
HandleAndAsset< Texture > normalTexture
Definition Material.hpp:22
HandleAndAsset< Texture > metallicTexture
Definition Material.hpp:24
HandleAndAsset< Texture > albedoTexture
Definition Material.hpp:21
HandleAndAsset< Texture > emissiveTexture
Definition Material.hpp:25