2020-06-02 11:46:18 +02:00
|
|
|
#include "AssetRegistry.h"
|
|
|
|
|
#include "MeshAsset.h"
|
|
|
|
|
#include "TextureAsset.h"
|
|
|
|
|
#include "TextureLoader.h"
|
|
|
|
|
#include "MaterialLoader.h"
|
|
|
|
|
#include "MeshLoader.h"
|
|
|
|
|
#include "Material/Material.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
2020-08-06 00:54:43 +02:00
|
|
|
#include "Graphics/WindowManager.h"
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
|
|
|
|
AssetRegistry::~AssetRegistry()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AssetRegistry::init(const std::string& rootFolder)
|
|
|
|
|
{
|
|
|
|
|
get().init(rootFolder, WindowManager::getGraphics());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AssetRegistry::importFile(const std::string &filePath)
|
|
|
|
|
{
|
2020-06-08 01:44:47 +02:00
|
|
|
std::filesystem::path fsPath = std::filesystem::path(filePath);
|
|
|
|
|
std::string extension = fsPath.extension().string();
|
2020-06-02 11:46:18 +02:00
|
|
|
std::cout << extension << std::endl;
|
2020-06-08 01:44:47 +02:00
|
|
|
if (extension.compare(".fbx") == 0
|
|
|
|
|
|| extension.compare(".obj") == 0)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
2020-06-08 01:44:47 +02:00
|
|
|
get().registerMesh(fsPath);
|
2020-06-02 11:46:18 +02:00
|
|
|
}
|
2020-06-08 01:44:47 +02:00
|
|
|
if (extension.compare(".png") == 0
|
|
|
|
|
|| extension.compare(".jpg") == 0)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
2020-06-08 01:44:47 +02:00
|
|
|
get().registerTexture(fsPath);
|
2020-06-02 11:46:18 +02:00
|
|
|
}
|
2020-06-08 01:44:47 +02:00
|
|
|
if (extension.compare(".semat") == 0)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
2020-06-08 01:44:47 +02:00
|
|
|
get().registerMaterial(fsPath);
|
2020-06-02 11:46:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PMeshAsset AssetRegistry::findMesh(const std::string &filePath)
|
|
|
|
|
{
|
|
|
|
|
return get().meshes[filePath];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath)
|
|
|
|
|
{
|
|
|
|
|
return get().materials[filePath];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PTextureAsset AssetRegistry::findTexture(const std::string &filePath)
|
|
|
|
|
{
|
|
|
|
|
return get().textures[filePath];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AssetRegistry &AssetRegistry::get()
|
|
|
|
|
{
|
|
|
|
|
static AssetRegistry instance;
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AssetRegistry::AssetRegistry()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 01:44:47 +02:00
|
|
|
void AssetRegistry::init(const std::filesystem::path &rootFolder, Gfx::PGraphics graphics)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
|
|
|
|
AssetRegistry ® = get();
|
|
|
|
|
reg.rootFolder = rootFolder;
|
|
|
|
|
reg.meshLoader = new MeshLoader(graphics);
|
|
|
|
|
reg.textureLoader = new TextureLoader(graphics);
|
|
|
|
|
reg.materialLoader = new MaterialLoader(graphics);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 01:44:47 +02:00
|
|
|
void AssetRegistry::registerMesh(const std::filesystem::path &filePath)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
|
|
|
|
meshLoader->importAsset(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 01:44:47 +02:00
|
|
|
void AssetRegistry::registerTexture(const std::filesystem::path &filePath)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
|
|
|
|
textureLoader->importAsset(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 01:44:47 +02:00
|
|
|
void AssetRegistry::registerMaterial(const std::filesystem::path &filePath)
|
2020-06-02 11:46:18 +02:00
|
|
|
{
|
|
|
|
|
materialLoader->queueAsset(filePath);
|
|
|
|
|
}
|