-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Basic Database, generating ids, and creating meta files
- Loading branch information
1 parent
b92147d
commit ac13c70
Showing
8 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,4 +397,5 @@ _deps | |
# External projects | ||
*-prefix/ | ||
|
||
*.arcmeta | ||
# End of https://www.toptal.com/developers/gitignore/api/cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
namespace Arcane | ||
{ | ||
enum class AssetType | ||
{ | ||
MESH | ||
}; | ||
|
||
class Asset | ||
{ | ||
public: | ||
Asset() {} | ||
|
||
int GetID() { return m_ID; } | ||
void SetID(int id) { m_ID = id; }; | ||
|
||
AssetType GetAssetType() { return m_Type; }; | ||
void SetAssetType(AssetType type) { m_Type = type; }; | ||
private: | ||
int m_ID = -1; | ||
AssetType m_Type; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <nlohmann/json.hpp> | ||
#include <time.h> | ||
#include <cstdlib> | ||
|
||
#include "MeshAsset.h" | ||
#include "AssetDatabase.h" | ||
|
||
|
||
namespace Arcane | ||
{ | ||
AssetDatabase::AssetDatabase(std::filesystem::path assetDir) | ||
{ | ||
m_AssetDirPath = assetDir; | ||
srand(time(0)); | ||
} | ||
|
||
Asset* AssetDatabase::GetAsset(int id) | ||
{ | ||
return m_Assets[id]; | ||
} | ||
|
||
bool AssetDatabase::GenerateDatabase() | ||
{ | ||
for (auto& dirEntry : std::filesystem::recursive_directory_iterator(m_AssetDirPath)) { | ||
if (dirEntry.is_regular_file()) { | ||
std::filesystem::path file = dirEntry.path(); | ||
|
||
bool isAssetGenerated = GenerateAsset(file); | ||
if (!isAssetGenerated) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool AssetDatabase::GenerateAsset(std::filesystem::path currentAssetPath) | ||
{ | ||
std::string metaFileName = currentAssetPath.stem().string() + ".arcmeta"; | ||
std::filesystem::path metaPath = currentAssetPath.parent_path() / metaFileName; | ||
|
||
// Either Create asset id or get from the meta file | ||
int assetID = 0; | ||
if (!CheckMetaInfo(metaPath)) { | ||
assetID = rand(); | ||
GenerateMetaFile(metaPath, assetID); | ||
} | ||
else { | ||
assetID = GetMetaID(metaPath); | ||
} | ||
|
||
// Get File extension | ||
if (currentAssetPath.extension() == ".obj") { | ||
MeshAsset* meshAsset = new MeshAsset(currentAssetPath); | ||
meshAsset->SetID(assetID); | ||
m_Assets[assetID] = meshAsset; | ||
} | ||
else if (currentAssetPath.extension() == ".fbx") { | ||
// Generate Mesh Asset | ||
} | ||
return true; | ||
} | ||
|
||
bool AssetDatabase::CheckMetaInfo(std::filesystem::path currentMetaPath) | ||
{ | ||
return std::filesystem::exists(currentMetaPath); | ||
} | ||
|
||
void AssetDatabase::GenerateMetaFile(std::filesystem::path metaPath, int newID) | ||
{ | ||
// Generate ID | ||
std::ofstream o(metaPath.string().c_str()); | ||
|
||
// Create json layout | ||
nlohmann::json meta_file; | ||
meta_file["id"] = newID; | ||
|
||
// save under .arcmeta file | ||
o << meta_file << std::endl; | ||
} | ||
|
||
int AssetDatabase::GetMetaID(std::filesystem::path currentMetaPath) | ||
{ | ||
nlohmann::json metaJson; | ||
std::ifstream i(currentMetaPath.string().c_str()); | ||
i >> metaJson; | ||
|
||
return metaJson["id"]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
#include <filesystem> | ||
|
||
#include "Asset.h" | ||
|
||
namespace Arcane | ||
{ | ||
class AssetDatabase | ||
{ | ||
public: | ||
AssetDatabase(std::filesystem::path assetDir); | ||
|
||
Asset* GetAsset(int id); | ||
|
||
bool GenerateDatabase(); | ||
bool GenerateAsset(std::filesystem::path currentAssetPath); | ||
|
||
bool CheckMetaInfo(std::filesystem::path currentMetaPath); | ||
void GenerateMetaFile(std::filesystem::path metaPath, int newID); | ||
|
||
int GetMetaID(std::filesystem::path metaPath); | ||
private: | ||
std::unordered_map<int, Asset*> m_Assets; | ||
std::filesystem::path m_AssetDirPath; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "MeshAsset.h" | ||
|
||
namespace Arcane | ||
{ | ||
MeshAsset::MeshAsset(std::filesystem::path meshPath) | ||
{ | ||
m_Mesh = new Mesh(meshPath.string()); | ||
SetAssetType(AssetType::MESH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#include <filesystem> | ||
#include "Asset.h" | ||
#include "Arcane/Renderer/Mesh.h" | ||
|
||
namespace Arcane | ||
{ | ||
class MeshAsset : public Asset | ||
{ | ||
public: | ||
MeshAsset(std::filesystem::path meshPath); | ||
|
||
|
||
Mesh* GetMesh() { return m_Mesh; } | ||
private: | ||
Mesh* m_Mesh; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters