mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Resource management refactor - added custom file resolver + RID
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user