NoJobEngine 2.0.7
Loading...
Searching...
No Matches
AssetManager.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <filesystem>
9#include <memory>
10#include <string>
11#include <unordered_map>
12#include <vector>
13
14namespace NoJob
15{
16 class Texture2D;
17 class Mesh;
18 class Shader;
19 class Material;
20
22 {
23 public:
24 static void Init(const std::filesystem::path& projectRoot);
25
26 static const std::filesystem::path& GetProjectRoot();
27 static const std::filesystem::path& GetAssetsDirectory();
28
29 // Resolves a project-relative path without depending on the process CWD.
30 // Absolute paths pass through normalized.
31 static std::filesystem::path ResolveProjectPath(
32 const std::filesystem::path& path);
33
34 // Copies an external image into Assets/Textures and returns
35 // a project-relative path such as Assets/Textures/brick.png.
36 static std::filesystem::path ImportTexture(
37 const std::filesystem::path& sourcePath);
38 static std::filesystem::path ImportModel(const std::filesystem::path& sourcePath);
39
40 // Reads the first material referenced by an imported model, imports
41 // its external/embedded textures and creates a persistent .nojobmat.
42 // This is the V1.1 automatic material pipeline. Multi-material
43 // submeshes are intentionally the next renderer-level extension.
44 static std::shared_ptr<Material> ImportModelMaterial(
45 const std::filesystem::path& modelPath,
46 const std::shared_ptr<Shader>& shader);
47 static std::vector<std::shared_ptr<Material>> ImportModelMaterials(
48 const std::filesystem::path& modelPath,
49 const std::shared_ptr<Shader>& shader);
50 static std::shared_ptr<Mesh> LoadMesh(const std::filesystem::path& path);
51 static std::filesystem::path GetMeshPath(const std::shared_ptr<Mesh>& mesh);
52
53 // Loads/caches a texture using a project-relative or absolute path.
54 static std::shared_ptr<Texture2D> LoadTexture(
55 const std::filesystem::path& path);
56
57 static std::filesystem::path ToProjectRelative(
58 const std::filesystem::path& path);
59
60 // Returns the canonical project-relative source path for a texture
61 // loaded by AssetManager. Empty means procedural/non-persistent.
62 static std::filesystem::path GetTexturePath(
63 const std::shared_ptr<Texture2D>& texture);
64
65 private:
66 static std::filesystem::path MakeUniqueDestination(
67 const std::filesystem::path& directory,
68 const std::filesystem::path& filename);
69
70 static std::filesystem::path s_ProjectRoot;
71 static std::filesystem::path s_AssetsDirectory;
72 static std::unordered_map<
73 std::string,
74 std::weak_ptr<Texture2D>> s_TextureCache;
75 static std::unordered_map<
76 const Texture2D*,
77 std::filesystem::path> s_TexturePaths;
78 static std::unordered_map<std::string,std::weak_ptr<Mesh>> s_MeshCache;
79 static std::unordered_map<const Mesh*,std::filesystem::path> s_MeshPaths;
80 };
81}
static const std::filesystem::path & GetProjectRoot()
static std::filesystem::path ToProjectRelative(const std::filesystem::path &path)
static std::filesystem::path GetTexturePath(const std::shared_ptr< Texture2D > &texture)
static std::filesystem::path ImportTexture(const std::filesystem::path &sourcePath)
static std::shared_ptr< Mesh > LoadMesh(const std::filesystem::path &path)
static std::shared_ptr< Texture2D > LoadTexture(const std::filesystem::path &path)
static const std::filesystem::path & GetAssetsDirectory()
static std::filesystem::path GetMeshPath(const std::shared_ptr< Mesh > &mesh)
static std::vector< std::shared_ptr< Material > > ImportModelMaterials(const std::filesystem::path &modelPath, const std::shared_ptr< Shader > &shader)
static void Init(const std::filesystem::path &projectRoot)
static std::shared_ptr< Material > ImportModelMaterial(const std::filesystem::path &modelPath, const std::shared_ptr< Shader > &shader)
static std::filesystem::path ImportModel(const std::filesystem::path &sourcePath)
static std::filesystem::path ResolveProjectPath(const std::filesystem::path &path)