Importing mesh asset now functioning
- Added debug logging for all user actions regarding FileDialog - Importing a Meshasset wil now Create a propery entity for the asset.
This commit is contained in:
parent
3fa5455b43
commit
2a5c7811e7
@ -41,7 +41,7 @@ void AssetManager::setAssetPath(std::filesystem::path path)
|
|||||||
|
|
||||||
YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path assetPath)
|
YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path assetPath)
|
||||||
{
|
{
|
||||||
YoggieEngine::Mesh imported;
|
YoggieEngine::Mesh* imported = nullptr;
|
||||||
|
|
||||||
std::ifstream AssetFile;
|
std::ifstream AssetFile;
|
||||||
AssetFile.open(assetPath, std::ios::binary);
|
AssetFile.open(assetPath, std::ios::binary);
|
||||||
@ -65,14 +65,16 @@ YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path
|
|||||||
std::cout << "Number of Elements: " << Enum << std::endl;
|
std::cout << "Number of Elements: " << Enum << std::endl;
|
||||||
free(Header);
|
free(Header);
|
||||||
|
|
||||||
|
|
||||||
|
imported = new YoggieEngine::Mesh();
|
||||||
// Load Vertices (Vertex + UV )
|
// Load Vertices (Vertex + UV )
|
||||||
imported.vertices = std::vector < YoggieEngine::Vertex>();
|
imported->vertices = std::vector < YoggieEngine::Vertex>();
|
||||||
for (int i = 0; i < Vnum; i++)
|
for (int i = 0; i < Vnum; i++)
|
||||||
{
|
{
|
||||||
YoggieEngine::Vertex data = YoggieEngine::Vertex();
|
YoggieEngine::Vertex data = YoggieEngine::Vertex();
|
||||||
AssetFile.read((char*)&data, Vsize);
|
AssetFile.read((char*)&data, Vsize);
|
||||||
|
|
||||||
imported.vertices.push_back(data);
|
imported->vertices.push_back(data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,11 +82,11 @@ YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path
|
|||||||
AssetFile.ignore(sizeof(char) * 3);
|
AssetFile.ignore(sizeof(char) * 3);
|
||||||
|
|
||||||
// Load Elements
|
// Load Elements
|
||||||
imported.elements = std::vector<unsigned int>();
|
imported->elements = std::vector<unsigned int>();
|
||||||
for (int i = 0; i < Enum; i++) {
|
for (int i = 0; i < Enum; i++) {
|
||||||
unsigned int data = 0;
|
unsigned int data = 0;
|
||||||
AssetFile.read((char*)&data, sizeof(unsigned int));
|
AssetFile.read((char*)&data, sizeof(unsigned int));
|
||||||
imported.elements.push_back(data);
|
imported->elements.push_back(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -92,8 +94,7 @@ YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path
|
|||||||
std::cout << "Failed ot open mesh " << std::endl;
|
std::cout << "Failed ot open mesh " << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return imported;
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -107,7 +108,7 @@ YoggieEngine::Renderable* AssetManager::LoadFromSource(const std::filesystem::pa
|
|||||||
std::cout << "Save path: " << MeshFileName << std::endl;
|
std::cout << "Save path: " << MeshFileName << std::endl;
|
||||||
|
|
||||||
std::ofstream meshAsset;
|
std::ofstream meshAsset;
|
||||||
meshAsset.open(MeshFileName.c_str(), std::ios::binary);
|
meshAsset.open(MeshFileName, std::ios::binary);
|
||||||
if (meshAsset.is_open()) {
|
if (meshAsset.is_open()) {
|
||||||
|
|
||||||
// write a header
|
// write a header
|
||||||
@ -123,7 +124,7 @@ YoggieEngine::Renderable* AssetManager::LoadFromSource(const std::filesystem::pa
|
|||||||
meshAsset.write((char*)&Vnum, sizeof(uint32_t));
|
meshAsset.write((char*)&Vnum, sizeof(uint32_t));
|
||||||
meshAsset.write((char*)&Enum, sizeof(uint32_t));
|
meshAsset.write((char*)&Enum, sizeof(uint32_t));
|
||||||
// write all vertices
|
// write all vertices
|
||||||
for (auto vertice : exportMesh->vertices)
|
for (auto& vertice : exportMesh->vertices)
|
||||||
{
|
{
|
||||||
meshAsset.write((char*)&vertice, sizeof(vertice));
|
meshAsset.write((char*)&vertice, sizeof(vertice));
|
||||||
}
|
}
|
||||||
|
@ -122,13 +122,27 @@ public:
|
|||||||
if (ImGui::MenuItem("Import MeshAsset (temp)"))
|
if (ImGui::MenuItem("Import MeshAsset (temp)"))
|
||||||
{
|
{
|
||||||
auto result = NFD_OpenDialog("mesh", NULL, &path);
|
auto result = NFD_OpenDialog("mesh", NULL, &path);
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
AssetManager::LoadFromAssetFile(path);
|
{
|
||||||
break;
|
YoggieEngine::Mesh* importedMesh = AssetManager::LoadFromAssetFile(path);
|
||||||
|
if (importedMesh != nullptr)
|
||||||
|
{
|
||||||
|
auto full_name = std::filesystem::path(path);
|
||||||
|
auto importedModel = scene.AddEntity(full_name.filename().u8string());
|
||||||
|
auto& rendererComponent = importedModel.AddComponent<Render3DComponent>();
|
||||||
|
rendererComponent.mesh = *importedMesh;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case(NFD_CANCEL):
|
case(NFD_CANCEL):
|
||||||
|
spdlog::debug("User cancelled action");
|
||||||
break;
|
break;
|
||||||
case(NFD_ERROR):
|
case(NFD_ERROR):
|
||||||
|
spdlog::warn("Something went wrong!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user