2024-12-27 01:34:34 +00:00
|
|
|
|
|
|
|
#include "Mesh.h"
|
2024-12-27 18:19:20 +00:00
|
|
|
#include "Engine/AssetManager.h"
|
|
|
|
#include "gcml.h"
|
|
|
|
|
|
|
|
#include "../Engine/AssetManager.h"
|
|
|
|
|
|
|
|
|
2024-12-27 18:47:48 +00:00
|
|
|
extern AssetManager g_AssetManager;
|
2024-12-27 01:34:34 +00:00
|
|
|
|
2024-12-27 05:42:36 +00:00
|
|
|
//TODO: Make this have a OBJ path, make indexCount derive from AssetManager
|
|
|
|
//TODO: and make texture id also get from AssetManager
|
|
|
|
//? Procastinate
|
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
const std::string MeshComponent::name = "Mesh";
|
|
|
|
|
|
|
|
MeshComponent::MeshComponent()
|
2024-12-27 18:19:20 +00:00
|
|
|
: vao(0), indexCount(0), textureID(0), MeshPath("assets/models/DefaultMesh.obj")
|
2024-12-27 01:34:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& MeshComponent::GetName() const
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& MeshComponent::GetStaticName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
YAML::Node MeshComponent::Serialize()
|
|
|
|
{
|
|
|
|
YAML::Node node;
|
|
|
|
|
|
|
|
node["vao"] = static_cast<int>(vao);
|
|
|
|
node["indexCount"] = static_cast<int>(indexCount);
|
|
|
|
node["textureID"] = static_cast<int>(textureID);
|
|
|
|
|
2024-12-27 18:19:20 +00:00
|
|
|
node["MeshPath"] = static_cast<std::string>(MeshPath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshComponent::Deserialize(const YAML::Node& node)
|
|
|
|
{
|
|
|
|
if (node["vao"])
|
|
|
|
{
|
|
|
|
vao = static_cast<int>(node["vao"].as<int>());
|
|
|
|
}
|
|
|
|
if (node["indexCount"])
|
|
|
|
{
|
|
|
|
indexCount = static_cast<int>(node["indexCount"].as<int>());
|
|
|
|
}
|
|
|
|
if (node["textureID"])
|
|
|
|
{
|
|
|
|
textureID = static_cast<int>(node["textureID"].as<int>());
|
|
|
|
}
|
2024-12-27 18:19:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (node["MeshPath"])
|
|
|
|
{
|
|
|
|
MeshPath = static_cast<std::string>(node["MeshPath"].as<std::string>());
|
2024-12-27 18:47:48 +00:00
|
|
|
g_AssetManager.DebugAssetMap();
|
2024-12-27 18:19:20 +00:00
|
|
|
|
2024-12-27 18:47:48 +00:00
|
|
|
#if 1
|
2024-12-27 18:19:20 +00:00
|
|
|
|
|
|
|
DEBUG_PRINT("Loading Mesh: >%s<", MeshPath.c_str());
|
|
|
|
|
2024-12-27 18:47:48 +00:00
|
|
|
Model* model = g_AssetManager.loadAsset<Model*>(AssetType::MODEL, MeshPath.c_str());
|
2024-12-27 18:19:20 +00:00
|
|
|
DEBUG_PRINT("Model loaded successfully with %lld vertices and %lld indices.", model->vertices.size(), model->indices.size());
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
DEBUG_PRINT("Automatic Mesh Loading Disabled.");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
2024-12-27 01:34:34 +00:00
|
|
|
}
|