Resource management refactor - added custom file resolver + RID

This commit is contained in:
antopilo
2025-01-18 17:51:49 -05:00
parent ab534fe929
commit 89ebc5d012
41 changed files with 1147 additions and 474 deletions

View File

@@ -58,7 +58,23 @@ public:
ImGui::TableNextColumn();
const char* lightTypes[] = { "Directional", "Point", "Spot" };
ComponentDropDown(lightTypes, Nuake::LightType, component.Type)
const char* current_item = lightTypes[(int)component.Type]; \
if (ImGui::BeginCombo("Type", current_item)) \
{ \
for (int n = 0; n < IM_ARRAYSIZE(lightTypes); n++) \
{ \
bool is_selected = (current_item == lightTypes[n]); \
if (ImGui::Selectable(lightTypes[n], is_selected)) \
{ \
current_item = lightTypes[n]; \
component.Type = (Nuake::LightType)n; \
} \
if (is_selected) \
ImGui::SetItemDefaultFocus(); \
} \
ImGui::EndCombo(); \
}
//ComponentDropDown(lightTypes, Nuake::LightType, component.Type)
ImGui::TableNextColumn();
ComponentTableReset(component.Type, Nuake::LightType::Point);

View File

@@ -44,10 +44,10 @@ public:
std::string label = "None";
const bool isModelNone = component.ModelResource == nullptr;
const bool isModelNone = component.ModelResource.Get<Model>() == nullptr;
if (!isModelNone)
{
label = std::to_string(component.ModelResource->ID);
label = std::to_string(component.ModelResource.ID);
}
if (ImGui::Button(label.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)))
@@ -56,7 +56,7 @@ public:
{
if (!_expanded)
{
_modelInspector = CreateScope<ModelResourceInspector>(component.ModelResource);
_modelInspector = CreateScope<ModelResourceInspector>(component.ModelResource.Get<Model>());
}
_expanded = !_expanded;
@@ -80,19 +80,19 @@ public:
if (Nuake::String::EndsWith(fullPath, ".mesh"))
{
component.ModelPath = fullPath;
component.ModelResource = ResourceLoader::LoadModel(fullPath);
//component.ModelResource = ResourceLoader::LoadModel(fullPath);
}
else
{
// Convert to .Model
component.ModelPath = fullPath;
component.LoadModel();
_importedPathMesh = fullPath;
auto loader = ModelLoader();
auto modelResource = loader.LoadModel(fullPath);
shouldConvert = true;
//component.ModelPath = fullPath;
//component.LoadModel();
//
//_importedPathMesh = fullPath;
//
//auto loader = ModelLoader();
//auto modelResource = loader.LoadModel(fullPath);
//shouldConvert = true;
}
}
ImGui::EndDragDropTarget();
@@ -101,20 +101,20 @@ public:
if (PopupHelper::DefineConfirmationDialog("##ConvertAsset", "Convert Asset"))
{
// Convert to disk
auto loader = ModelLoader();
Ref<Model> modelResource = loader.LoadModel(_importedPathMesh);
json serializedData = modelResource->SerializeData();
const std::string exportedMeshPath = _importedPathMesh + ".mesh";
FileSystem::BeginWriteFile(exportedMeshPath);
FileSystem::WriteLine(serializedData.dump());
FileSystem::EndWriteFile();
ResourceManager::RegisterResource(modelResource);
// Update component
component.ModelPath = exportedMeshPath;
component.ModelResource = modelResource;
//auto loader = ModelLoader();
//Ref<Model> modelResource = loader.LoadModel(_importedPathMesh);
//json serializedData = modelResource->SerializeData();
//
//const std::string exportedMeshPath = _importedPathMesh + ".mesh";
//FileSystem::BeginWriteFile(exportedMeshPath);
//FileSystem::WriteLine(serializedData.dump());
//FileSystem::EndWriteFile();
//
//ResourceManager::RegisterResource(modelResource);
//
//// Update component
//component.ModelPath = exportedMeshPath;
//component.ModelResource = modelResource;
}
if (shouldConvert)

View File

@@ -363,7 +363,7 @@ public:
auto& transformComponent = brush.GetComponent<TransformComponent>();
auto& modelComponent = brush.GetComponent<ModelComponent>();
for (auto& mesh : modelComponent.ModelResource->GetMeshes())
for (auto& mesh : modelComponent.ModelResource.Get<Model>()->GetMeshes())
{
Nuake::NavManager::Get().PushMesh(mesh, transformComponent.GetGlobalTransform());
}