Fixed Loading Overwriting Invalid Values

This commit is contained in:
OusmBlueNinja 2024-12-27 12:59:05 -06:00
parent 1a9f9eda39
commit acae54d70d
6 changed files with 48 additions and 68 deletions

View File

@ -1,6 +1,6 @@
[Window][DockSpace]
Pos=0,0
Size=1920,1177
Size=1280,720
Collapsed=0
[Window][Debug##Default]
@ -9,8 +9,8 @@ Size=400,400
Collapsed=0
[Window][Inspector]
Pos=1543,27
Size=369,1142
Pos=903,27
Size=369,685
Collapsed=0
DockId=0x00000002,0
@ -21,14 +21,14 @@ Collapsed=0
DockId=0x00000003,0
[Window][Performance]
Pos=8,777
Size=364,392
Pos=8,477
Size=364,235
Collapsed=0
DockId=0x00000006,0
[Window][Logger]
Pos=374,799
Size=1167,370
Pos=374,342
Size=527,370
Collapsed=0
DockId=0x00000004,0
@ -40,18 +40,18 @@ DockId=0x00000007,0
[Window][Scene Window]
Pos=8,27
Size=364,748
Size=364,448
Collapsed=0
DockId=0x00000005,0
[Window][Editor]
Pos=374,27
Size=1167,770
Size=527,313
Collapsed=0
DockId=0x00000003,0
[Docking][Data]
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1142 Split=X Selected=0xF7365A5A
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1264,685 Split=X Selected=0xF7365A5A
DockNode ID=0x00000009 Parent=0x14621557 SizeRef=364,1142 Split=Y Selected=0x3DC5AC3F
DockNode ID=0x00000005 Parent=0x00000009 SizeRef=364,748 HiddenTabBar=1 Selected=0x3DC5AC3F
DockNode ID=0x00000006 Parent=0x00000009 SizeRef=364,392 HiddenTabBar=1 Selected=0x726D8899

View File

@ -1,37 +1,13 @@
Entities:
- ID: 0
Name: Car
Name: Default
Components:
Transform:
Position: [1, 1.10000002, -4.30000019]
Rotation: [-21.5, -65.3000031, -180]
Scale: [1, 1, 1]
Mesh:
vao: 2
indexCount: 15810
vao: 1
indexCount: 36
textureID: 1
MeshPath: assets/models/DefaultMesh.obj
- ID: 1
Name: Shopping Cart
Components:
Transform:
Position: [-1.39999998, 1, 1.20000005]
Rotation: [-180, -136, 0]
Scale: [2, 2, 2]
Mesh:
vao: 3
indexCount: 2304
textureID: 5
MeshPath: assets/models/DefaultMesh.obj
- ID: 2
Name: Skybox
Components:
Mesh:
vao: 5
indexCount: 36
textureID: 6
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [0, 0, -190.5]
Rotation: [0, -56.5999985, 0]
Scale: [200, 200, 200]
Position: [0, 0, 0]
Rotation: [0, 0.5, 0]
Scale: [1, 1, 1]

View File

@ -5,11 +5,10 @@
#include "../Engine/AssetManager.h"
extern AssetManager g_AssetManager;
//TODO: Make this have a OBJ path, make indexCount derive from AssetManager
//TODO: and make texture id also get from AssetManager
// TODO: Make this have a OBJ path, make indexCount derive from AssetManager
// TODO: and make texture id also get from AssetManager
//? Procastinate
const std::string MeshComponent::name = "Mesh";
@ -19,12 +18,12 @@ MeshComponent::MeshComponent()
{
}
const std::string& MeshComponent::GetName() const
const std::string &MeshComponent::GetName() const
{
return name;
}
const std::string& MeshComponent::GetStaticName()
const std::string &MeshComponent::GetStaticName()
{
return name;
}
@ -32,23 +31,17 @@ const std::string& MeshComponent::GetStaticName()
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);
node["MeshPath"] = static_cast<std::string>(MeshPath);
return node;
}
void MeshComponent::Deserialize(const YAML::Node& node)
void MeshComponent::Deserialize(const YAML::Node &node)
{
if (node["vao"])
{
@ -63,23 +56,35 @@ void MeshComponent::Deserialize(const YAML::Node& node)
textureID = static_cast<int>(node["textureID"].as<int>());
}
if (node["MeshPath"])
{
MeshPath = static_cast<std::string>(node["MeshPath"].as<std::string>());
g_AssetManager.DebugAssetMap();
// g_AssetManager.DebugAssetMap();
#if 1
#if 1
DEBUG_PRINT("Loading Mesh: >%s<", MeshPath.c_str());
DEBUG_PRINT("Loading Mesh: %s", MeshPath.c_str());
Model* model = g_AssetManager.loadAsset<Model*>(AssetType::MODEL, MeshPath.c_str());
DEBUG_PRINT("Model loaded successfully with %lld vertices and %lld indices.", model->vertices.size(), model->indices.size());
#else
Model *model = g_AssetManager.loadAsset<Model *>(AssetType::MODEL, MeshPath.c_str());
DEBUG_PRINT("Model loaded successfully with %lld vertices and %lld indices.", model->vertices.size(), model->indices.size());
if (model->vao != 0)
{
vao = model->vao;
}
if (model->indices.size() != 0)
{
indexCount = model->indices.size();
}
if (textureID != 0)
{
textureID = model->textureID;
}
#else
DEBUG_PRINT("Automatic Mesh Loading Disabled.");
#endif
#endif
}
}

View File

@ -52,7 +52,7 @@ void AssetManager::DebugAssetMap()
// Implementation of AssetManager::loadAssetFromDisk
AssetManager::AssetVariant AssetManager::loadAssetFromDisk(AssetType type, const std::string &path)
{
DebugAssetMap();
//DebugAssetMap();
switch (type)
{
case AssetType::TEXTURE:

View File

@ -75,7 +75,7 @@ public:
if (it != m_AssetMap.end())
{
// Debug: Log the variant type
std::cout << "[AssetManager] Found asset in map." << std::endl;
DEBUG_PRINT("[AssetManager] Found asset in map.");
if (std::holds_alternative<T>(it->second))
{
return std::get<T>(it->second);

View File

@ -332,11 +332,10 @@ void InspectorWindow::Show()
// Update the string if user made changes
mesh->MeshPath = buffer;
}
float availableWidth = ImGui::GetContentRegionAvail().x;
ImGui::Image(mesh->textureID, ImVec2(availableWidth, availableWidth), ImVec2(0, 0), ImVec2(1, 1));
}
float availableWidth = ImGui::GetContentRegionAvail().x;
ImGui::Image(mesh->textureID, ImVec2(availableWidth,availableWidth), ImVec2(0, 0), ImVec2(1, 1));
}
ImGui::Spacing();