#include "src/Resource/Model.h" #include "src/Core/FileSystem.h" #include "src/Core/Logger.h" #include "src/Rendering/Mesh/Mesh.h" #include "src/Resource/ModelLoader.h" namespace Nuake { Model::Model(const std::string path) : m_Meshes(std::vector>()) { this->Path = path; } Model::Model() : m_Meshes(std::vector>()) {} Model::~Model() {} void Model::AddMesh(Ref mesh) { m_Meshes.push_back(mesh); } std::vector>& Model::GetMeshes() { return m_Meshes; } json Model::Serialize() { BEGIN_SERIALIZE(); if (this->Path != "") { j["Path"] = this->Path; } else { for (uint32_t i = 0; i < std::size(m_Meshes); i++) { j["Meshes"][i] = m_Meshes[i]->Serialize(); } } END_SERIALIZE(); } bool Model::Deserialize(const json& j) { if (j.contains("Path")) { this->IsEmbedded = true; ModelLoader loader; auto otherModel = loader.LoadModel(j["Path"], false); m_Meshes = otherModel->GetMeshes(); this->Path = j["Path"]; } else { for (auto& m : j["Meshes"]) { Ref mesh = CreateRef(); mesh->Deserialize(m); m_Meshes.push_back(mesh); } } return true; } }