diff --git a/assets/editor/localization.csv b/assets/editor/localization.csv index 9481cad..a1f0f23 100644 --- a/assets/editor/localization.csv +++ b/assets/editor/localization.csv @@ -14,6 +14,8 @@ LOC_EDITOR_MENU_LOG_COPY;Copy;Copier LOC_EDITOR_MENU_IMPORT;Import;Importer LOC_EDITOR_MENU_TOOLS;Tools;Outils LOC_EDITOR_MENU_LANGUAGE;Language;Langue +LOC_EDITOR_MENU_VIEW;View;Fenetre +LOC_EDITOR_MENU_RESOLUTION;Resolution;Résolution LOC_EDITOR_ACTION_LEVEL_NEW_DESC;Create new level;Créé un nouveau niveau LOC_EDITOR_ACTION_LEVEL_OPEN_DESC;Open a level;Ouvre un niveau LOC_EDITOR_ACTION_LEVEL_SAVE_DESC;Save current level;Sauvegarde le niveau actuel diff --git a/include/NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp b/include/NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp new file mode 100644 index 0000000..037ed7f --- /dev/null +++ b/include/NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include + +#include + +namespace Nz +{ + NAZARAEDITOR_CORE_API void RegisterCameraActions(class EditorBaseApplication& app); + + class NAZARAEDITOR_CORE_API EditorAction_SetCameraSize final + : public EditorAction + { + public: + EditorAction_SetCameraSize(const Properties& properties, const Nz::Vector2ui& size) + : EditorAction(properties) + , m_size(size) + {} + EditorAction_SetCameraSize(const std::shared_ptr& properties, const Nz::Vector2ui& size) + : EditorAction(properties) + , m_size(size) + {} + ~EditorAction_SetCameraSize() = default; + + std::unique_ptr Clone() const override { return std::make_unique(m_properties, m_size); } + const std::string& GetName() const override { return m_properties->className; } + bool IsUndoRedoable() const override { return false; } + static const char* GetClassName() { return "EditorAction_SetCameraSize"; } + + void Execute() override; + + protected: + Nz::Vector2ui m_size; + }; +} \ No newline at end of file diff --git a/include/NazaraEditor/Core/Application/BaseApplication.hpp b/include/NazaraEditor/Core/Application/BaseApplication.hpp index 743beaf..f0b8e3c 100644 --- a/include/NazaraEditor/Core/Application/BaseApplication.hpp +++ b/include/NazaraEditor/Core/Application/BaseApplication.hpp @@ -83,7 +83,11 @@ namespace Nz inline Nz::Texture* GetEngineTexture() { return m_engineTexture.get(); } inline const Nz::Texture* GetEngineTexture() const { return m_engineTexture.get(); } + void CreateEngineTexture(const Nz::Vector2ui& resolution); + private: + void CreateEngineCamera(); + static EditorBaseApplication* s_instance; Nz::Window* m_window; diff --git a/src/NazaraEditor/Core/Application/Actions/EditorAction_Camera.cpp b/src/NazaraEditor/Core/Application/Actions/EditorAction_Camera.cpp new file mode 100644 index 0000000..3afa299 --- /dev/null +++ b/src/NazaraEditor/Core/Application/Actions/EditorAction_Camera.cpp @@ -0,0 +1,30 @@ +#include + +#include + +namespace Nz +{ + void RegisterCameraActions(EditorBaseApplication& app) + { + for (auto&& size : std::vector{ + { 320, 340 }, { 640, 480 }, { 800, 600 }, { 1024, 768 }, + { 1280, 720 }, { 1280, 960 }, { 1280, 1024 }, + { 1366, 768 }, { 1440, 900 }, + { 1920, 1080 }, { 1920, 1200 }, + }) + { + auto str = std::format("{} x {}", size.x, size.y); + app.RegisterAction({ + .className = std::format("{}_{}x{}", Nz::EditorAction_SetCameraSize::GetClassName(), size.x, size.y), + .description = str.c_str(), + .path = { "LOC_EDITOR_MENU_VIEW", "LOC_EDITOR_MENU_RESOLUTION", str.c_str()}, + .category = "Tools", + }, size); + } + } + + void EditorAction_SetCameraSize::Execute() + { + Nz::EditorBaseApplication::Instance()->CreateEngineTexture(m_size); + } +} \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/BaseApplication.cpp b/src/NazaraEditor/Core/Application/BaseApplication.cpp index 0213261..213335f 100644 --- a/src/NazaraEditor/Core/Application/BaseApplication.cpp +++ b/src/NazaraEditor/Core/Application/BaseApplication.cpp @@ -37,22 +37,7 @@ namespace Nz m_windowSwapchain = std::make_unique(device, window); m_window = &window; - // Allocate texture for engine rendering - { - Nz::TextureInfo screenTextureInfo = { - .pixelFormat = Nz::PixelFormat::RGBA8, - .type = Nz::ImageType::E2D, - .usageFlags = Nz::TextureUsage::ColorAttachment | Nz::TextureUsage::ShaderSampling | Nz::TextureUsage::TransferDestination, - .levelCount = 1, - .height = 720, - .width = 1280 - }; - - std::size_t size = Nz::PixelFormatInfo::ComputeSize(screenTextureInfo.pixelFormat, screenTextureInfo.width, screenTextureInfo.height, screenTextureInfo.depth); - - std::vector defaultScreen(size, 0xFF); - m_engineTexture = device->InstantiateTexture(screenTextureInfo, defaultScreen.data(), false); - } + CreateEngineTexture({ 1280, 720 }); // connect basic handler window.GetEventHandler().OnQuit.Connect([&window](const auto* handler) { @@ -134,16 +119,56 @@ namespace Nz auto& cmp = m_mainCamera.get(); cmp.SetFlags(EditorEntityFlags_Hidden); - auto passList = Nz::PipelinePassList::LoadFromFile(m_resourceFolder / "engine.passlist"); - - auto& cameraComponent = m_mainCamera.emplace(std::make_shared(m_engineTexture), passList, Nz::ProjectionType::Perspective); - cameraComponent.UpdateFOV(70.f); - cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f)); - - m_mainCamera.emplace(cameraComponent, system.GetFramePipeline().GetDebugDrawer()); + CreateEngineCamera(); OnLevelChanged(m_level); } return bRes; } + + // Allocate texture for engine rendering + void EditorBaseApplication::CreateEngineTexture(const Nz::Vector2ui& resolution) + { + std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); + + Nz::TextureInfo screenTextureInfo = { + .pixelFormat = Nz::PixelFormat::RGBA8, + .type = Nz::ImageType::E2D, + .usageFlags = Nz::TextureUsage::ColorAttachment | Nz::TextureUsage::ShaderSampling | Nz::TextureUsage::TransferDestination, + .levelCount = 1, + .height = resolution.y, + .width = resolution.x + }; + + std::size_t size = Nz::PixelFormatInfo::ComputeSize(screenTextureInfo.pixelFormat, screenTextureInfo.width, screenTextureInfo.height, screenTextureInfo.depth); + + std::vector defaultScreen(size, 0xFF); + m_engineTexture = device->InstantiateTexture(screenTextureInfo, defaultScreen.data(), false); + + if (m_mainCamera) + { + m_mainCamera.remove(); + m_mainCamera.remove(); + CreateEngineCamera(); + } + + } + + void EditorBaseApplication::CreateEngineCamera() + { + RenderSystem& system = m_level.GetEnttWorld()->GetSystem(); + + auto passList = Nz::PipelinePassList::LoadFromFile(m_resourceFolder / "engine.passlist"); + + auto& cameraComponent = m_mainCamera.emplace(std::make_shared(m_engineTexture), passList, Nz::ProjectionType::Perspective); + cameraComponent.UpdateFOV(70.f); + cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f)); + + auto& editorCameraComponent = m_mainCamera.emplace(cameraComponent, system.GetFramePipeline().GetDebugDrawer()); + auto& transform = m_mainCamera.get(); + + editorCameraComponent.SetPosition(transform.GetPosition()); + editorCameraComponent.SetRotation(transform.GetRotation()); + + } } \ No newline at end of file diff --git a/src/NazaraEditor/Editor/Application.cpp b/src/NazaraEditor/Editor/Application.cpp index 3c3d4d4..4877a8f 100644 --- a/src/NazaraEditor/Editor/Application.cpp +++ b/src/NazaraEditor/Editor/Application.cpp @@ -14,6 +14,8 @@ #include +#include + namespace NzEditor { Application::Application() @@ -26,6 +28,7 @@ namespace NzEditor Nz::RegisterLevelActions(*this); Nz::RegisterEditorActions(*this); + Nz::RegisterCameraActions(*this); Nz::RegisterLogActions(*this); Nz::Localization::OnLocaleInstalled.Connect([this](std::string_view locale) {