Lugdunum  0.1.0
GltfLoader.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 #include <gltf2/glTF2.hpp>
6 
13 
14 namespace lug {
15 namespace Graphics {
16 
17 class Renderer;
18 
22 class LUG_GRAPHICS_API GltfLoader final : public Loader {
23 private:
24  struct LoadedAssets {
25  std::vector<Resource::SharedPtr<Render::Texture>> textures;
27  std::vector<Resource::SharedPtr<Render::Material>> materials;
28  std::vector<Resource::SharedPtr<Render::Mesh>> meshes;
29  };
30 
31 public:
32  GltfLoader(Renderer& renderer);
33 
34  GltfLoader(const GltfLoader&) = delete;
35  GltfLoader(GltfLoader&&) = delete;
36 
37  GltfLoader& operator=(const GltfLoader&) = delete;
38  GltfLoader& operator=(GltfLoader&&) = delete;
39 
40  ~GltfLoader() = default;
41 
47  Resource::SharedPtr<Resource> loadFile(const std::string& filename) override final;
48 
49 private:
50  Resource::SharedPtr<Render::Texture> createTexture(Renderer& renderer, const gltf2::Asset& asset, GltfLoader::LoadedAssets& loadedAssets, int32_t index);
51  Resource::SharedPtr<Render::Material> createMaterial(Renderer& renderer, const gltf2::Asset& asset, GltfLoader::LoadedAssets& loadedAssets, int32_t index);
52  Resource::SharedPtr<Render::Material> createDefaultMaterial(Renderer& renderer, GltfLoader::LoadedAssets& loadedAssets);
53  Resource::SharedPtr<Render::Mesh> createMesh(Renderer& renderer, const gltf2::Asset& asset, GltfLoader::LoadedAssets& loadedAssets, int32_t index);
54  bool createNode(Renderer& renderer, const gltf2::Asset& asset, GltfLoader::LoadedAssets& loadedAssets, int32_t index, Scene::Node& parent);
55 };
56 
57 } // Graphics
58 } // lug
Class for loading a type of file.
Definition: Loader.hpp:16
#define LUG_GRAPHICS_API
Definition: Export.hpp:11
std::vector< Resource::SharedPtr< Render::Texture > > textures
Definition: GltfLoader.hpp:25
Dummy class for a shared pointer.
Definition: Resource.hpp:66
std::vector< Resource::SharedPtr< Render::Material > > materials
Definition: GltfLoader.hpp:27
std::vector< Resource::SharedPtr< Render::Mesh > > meshes
Definition: GltfLoader.hpp:28
Resource::SharedPtr< Render::Material > defaultMaterial
Definition: GltfLoader.hpp:26
Class for loading glTF files.
Definition: GltfLoader.hpp:22