mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Added a way to make mesh external instead of always embedded into the scene
This commit is contained in:
@@ -2,18 +2,22 @@
|
||||
#include <src/Core/Core.h>
|
||||
#include "ComponentPanel.h"
|
||||
#include "ModelResourceInspector.h"
|
||||
#include "../Misc/PopupHelper.h"
|
||||
|
||||
#include <src/Scene/Entities/ImGuiHelper.h>
|
||||
#include <src/Scene/Components/ModelComponent.h>
|
||||
|
||||
#include <src/Resource/ResourceLoader.h>
|
||||
#include <src/Core/String.h>
|
||||
#include <src/Resource/ModelLoader.h>
|
||||
|
||||
class MeshPanel : ComponentPanel
|
||||
{
|
||||
private:
|
||||
Scope<ModelResourceInspector> _modelInspector;
|
||||
bool _expanded = false;
|
||||
|
||||
std::string _importedPathMesh;
|
||||
public:
|
||||
MeshPanel()
|
||||
{
|
||||
@@ -58,6 +62,7 @@ public:
|
||||
_modelInspector->Draw();
|
||||
}
|
||||
|
||||
bool shouldConvert = false;
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Model"))
|
||||
@@ -66,19 +71,51 @@ public:
|
||||
std::string fullPath = std::string(file, 256);
|
||||
fullPath = Nuake::FileSystem::AbsoluteToRelative(fullPath);
|
||||
|
||||
if (Nuake::String::EndsWith(fullPath, ".model"))
|
||||
if (Nuake::String::EndsWith(fullPath, ".mesh"))
|
||||
{
|
||||
|
||||
component.ModelPath = 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;
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (shouldConvert)
|
||||
{
|
||||
PopupHelper::OpenPopup("##ConvertAsset");
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.ModelPath, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user