feat: add selection to meshrendercomponent

This commit is contained in:
2026-10-22 22:24:59 +02:00
parent f99147b1a2
commit f055bdcbf1
16 changed files with 1103 additions and 68 deletions
+30
View File
@@ -10,7 +10,10 @@
#include <destrum/Graphics/Managers/Renderer2D.h>
#include <destrum/Input/InputManager.h>
#include <destrum/ObjectModel/GameObject.h>
#include <destrum/Scene/ModelSpawner.h>
#include <destrum/Scene/Scene.h>
#include <destrum/Util/AssetBrowser.h>
#include <destrum/Util/ModelDoc.h>
#include <destrum/Serialization/PrefabSerializer.h>
#include <destrum/Serialization/SceneSerializer.h>
@@ -23,6 +26,7 @@
#include <string_view>
#include "imgui.h"
#include "spdlog/spdlog.h"
namespace {
std::filesystem::path ResolveScenePath(
@@ -187,6 +191,32 @@ void LightKeeper::drawDebugMenuBar()
ImGui::EndMainMenuBar();
}
void LightKeeper::onViewportAssetDropped(std::string_view path)
{
if (!AssetBrowser::IsModel(path)) {
sceneStatus = "Only models can be dropped in the viewport: " + std::string{path};
return;
}
ModelDoc::LoadOptions options{};
options.meshImportMode = ModelDoc::MeshImportMode::MergedPerNode;
options.loadMaterials = true;
try {
Scene& scene = SceneManager::GetInstance().GetCurrentScene();
const std::string name = std::filesystem::path{path}.stem().string();
GameObject* model = ModelSpawner::SpawnStaticModel(scene, gfxDevice, resources, path, options, name);
const Camera& view = getViewCamera();
model->GetTransform().SetWorldPosition(view.GetPosition() + view.GetForward() * 5.0f);
scene.SetSelectedObject(model->GetId());
sceneStatus = "Placed " + std::string{path};
} catch (const std::exception& exception) {
spdlog::error("Could not place {}: {}", path, exception.what());
sceneStatus = "Could not place " + std::string{path};
}
}
void LightKeeper::drawViewportOverlay()
{
if (!showTransformGizmo || isPlayerViewActive()) {