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());
}

View File

@@ -433,12 +433,12 @@ void GizmoDrawer::DrawShapes(Ref<Scene> scene, bool occluded)
auto [transform, mesh, model] = scene->m_Registry.get<TransformComponent, MeshColliderComponent, ModelComponent>(e);
// Component has no mesh set.
if (!model.ModelResource)
if (!model.ModelResource.Get<Model>())
{
continue;
}
auto& resource = model.ModelResource;
auto resource = model.ModelResource.Get<Model>();
const auto& meshes = resource->GetMeshes();
if (mesh.SubMesh >= meshes.size())

View File

@@ -718,18 +718,18 @@ namespace Nuake {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Model"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
fullPath = Nuake::FileSystem::AbsoluteToRelative(fullPath);
auto loader = ModelLoader();
auto modelResource = loader.LoadModel(fullPath);
auto entity = Engine::GetCurrentScene()->CreateEntity(FileSystem::GetFileNameFromPath(fullPath));
ModelComponent& modelComponent = entity.AddComponent<ModelComponent>();
modelComponent.ModelPath = fullPath;
modelComponent.ModelResource = modelResource;
entity.GetComponent<TransformComponent>().SetLocalPosition(dragnDropWorldPos);
//char* file = (char*)payload->Data;
//std::string fullPath = std::string(file, 256);
//fullPath = Nuake::FileSystem::AbsoluteToRelative(fullPath);
//
//auto loader = ModelLoader();
//auto modelResource = loader.LoadModel(fullPath);
//
//auto entity = Engine::GetCurrentScene()->CreateEntity(FileSystem::GetFileNameFromPath(fullPath));
//ModelComponent& modelComponent = entity.AddComponent<ModelComponent>();
//modelComponent.ModelPath = fullPath;
//modelComponent.ModelResource = modelResource;
//entity.GetComponent<TransformComponent>().SetLocalPosition(dragnDropWorldPos);
}
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map"))

View File

@@ -677,7 +677,6 @@ namespace Nuake
}
Ref<Material> material = CreateRef<Material>();
material->IsEmbedded = false;
auto jsonData = material->Serialize();
FileSystem::BeginWriteFile(finalPath, true);
@@ -699,7 +698,6 @@ namespace Nuake
}
Ref<SkyResource> sky = CreateRef<SkyResource>(FileSystem::AbsoluteToRelative(finalPath));
sky->IsEmbedded = false;
auto jsonData = sky->Serialize();
FileSystem::BeginWriteFile(finalPath, true);
@@ -721,7 +719,6 @@ namespace Nuake
}
Ref<Environment> env = CreateRef<Environment>(FileSystem::AbsoluteToRelative(finalPath));
env->IsEmbedded = false;
auto jsonData = env->Serialize();
FileSystem::BeginWriteFile(finalPath, true);