Add Camera resolution change action
This commit is contained in:
@@ -14,6 +14,8 @@ LOC_EDITOR_MENU_LOG_COPY;Copy;Copier
|
|||||||
LOC_EDITOR_MENU_IMPORT;Import;Importer
|
LOC_EDITOR_MENU_IMPORT;Import;Importer
|
||||||
LOC_EDITOR_MENU_TOOLS;Tools;Outils
|
LOC_EDITOR_MENU_TOOLS;Tools;Outils
|
||||||
LOC_EDITOR_MENU_LANGUAGE;Language;Langue
|
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_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_OPEN_DESC;Open a level;Ouvre un niveau
|
||||||
LOC_EDITOR_ACTION_LEVEL_SAVE_DESC;Save current level;Sauvegarde le niveau actuel
|
LOC_EDITOR_ACTION_LEVEL_SAVE_DESC;Save current level;Sauvegarde le niveau actuel
|
||||||
|
|||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <NazaraEditor/Core/Application/Action.hpp>
|
||||||
|
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
|
||||||
|
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>& properties, const Nz::Vector2ui& size)
|
||||||
|
: EditorAction(properties)
|
||||||
|
, m_size(size)
|
||||||
|
{}
|
||||||
|
~EditorAction_SetCameraSize() = default;
|
||||||
|
|
||||||
|
std::unique_ptr<EditorAction> Clone() const override { return std::make_unique<EditorAction_SetCameraSize>(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;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -83,7 +83,11 @@ namespace Nz
|
|||||||
inline Nz::Texture* GetEngineTexture() { return m_engineTexture.get(); }
|
inline Nz::Texture* GetEngineTexture() { return m_engineTexture.get(); }
|
||||||
inline const Nz::Texture* GetEngineTexture() const { return m_engineTexture.get(); }
|
inline const Nz::Texture* GetEngineTexture() const { return m_engineTexture.get(); }
|
||||||
|
|
||||||
|
void CreateEngineTexture(const Nz::Vector2ui& resolution);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CreateEngineCamera();
|
||||||
|
|
||||||
static EditorBaseApplication* s_instance;
|
static EditorBaseApplication* s_instance;
|
||||||
|
|
||||||
Nz::Window* m_window;
|
Nz::Window* m_window;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include <NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp>
|
||||||
|
|
||||||
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
void RegisterCameraActions(EditorBaseApplication& app)
|
||||||
|
{
|
||||||
|
for (auto&& size : std::vector<Nz::Vector2ui>{
|
||||||
|
{ 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<Nz::EditorAction_SetCameraSize>({
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,22 +37,7 @@ namespace Nz
|
|||||||
m_windowSwapchain = std::make_unique<Nz::WindowSwapchain>(device, window);
|
m_windowSwapchain = std::make_unique<Nz::WindowSwapchain>(device, window);
|
||||||
m_window = &window;
|
m_window = &window;
|
||||||
|
|
||||||
// Allocate texture for engine rendering
|
CreateEngineTexture({ 1280, 720 });
|
||||||
{
|
|
||||||
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<std::uint8_t> defaultScreen(size, 0xFF);
|
|
||||||
m_engineTexture = device->InstantiateTexture(screenTextureInfo, defaultScreen.data(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// connect basic handler
|
// connect basic handler
|
||||||
window.GetEventHandler().OnQuit.Connect([&window](const auto* handler) {
|
window.GetEventHandler().OnQuit.Connect([&window](const auto* handler) {
|
||||||
@@ -134,16 +119,56 @@ namespace Nz
|
|||||||
auto& cmp = m_mainCamera.get<Nz::EditorNameComponent>();
|
auto& cmp = m_mainCamera.get<Nz::EditorNameComponent>();
|
||||||
cmp.SetFlags(EditorEntityFlags_Hidden);
|
cmp.SetFlags(EditorEntityFlags_Hidden);
|
||||||
|
|
||||||
auto passList = Nz::PipelinePassList::LoadFromFile(m_resourceFolder / "engine.passlist");
|
CreateEngineCamera();
|
||||||
|
|
||||||
auto& cameraComponent = m_mainCamera.emplace<Nz::CameraComponent>(std::make_shared<Nz::RenderTexture>(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<Nz::EditorCameraComponent>(cameraComponent, system.GetFramePipeline().GetDebugDrawer());
|
|
||||||
|
|
||||||
OnLevelChanged(m_level);
|
OnLevelChanged(m_level);
|
||||||
}
|
}
|
||||||
return bRes;
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allocate texture for engine rendering
|
||||||
|
void EditorBaseApplication::CreateEngineTexture(const Nz::Vector2ui& resolution)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Nz::RenderDevice> 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<std::uint8_t> defaultScreen(size, 0xFF);
|
||||||
|
m_engineTexture = device->InstantiateTexture(screenTextureInfo, defaultScreen.data(), false);
|
||||||
|
|
||||||
|
if (m_mainCamera)
|
||||||
|
{
|
||||||
|
m_mainCamera.remove<Nz::EditorCameraComponent>();
|
||||||
|
m_mainCamera.remove<Nz::CameraComponent>();
|
||||||
|
CreateEngineCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorBaseApplication::CreateEngineCamera()
|
||||||
|
{
|
||||||
|
RenderSystem& system = m_level.GetEnttWorld()->GetSystem<RenderSystem>();
|
||||||
|
|
||||||
|
auto passList = Nz::PipelinePassList::LoadFromFile(m_resourceFolder / "engine.passlist");
|
||||||
|
|
||||||
|
auto& cameraComponent = m_mainCamera.emplace<Nz::CameraComponent>(std::make_shared<Nz::RenderTexture>(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<Nz::EditorCameraComponent>(cameraComponent, system.GetFramePipeline().GetDebugDrawer());
|
||||||
|
auto& transform = m_mainCamera.get<Nz::NodeComponent>();
|
||||||
|
|
||||||
|
editorCameraComponent.SetPosition(transform.GetPosition());
|
||||||
|
editorCameraComponent.SetRotation(transform.GetRotation());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include <NazaraLocalization/Localization.hpp>
|
#include <NazaraLocalization/Localization.hpp>
|
||||||
|
|
||||||
|
#include <NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp>
|
||||||
|
|
||||||
namespace NzEditor
|
namespace NzEditor
|
||||||
{
|
{
|
||||||
Application::Application()
|
Application::Application()
|
||||||
@@ -26,6 +28,7 @@ namespace NzEditor
|
|||||||
|
|
||||||
Nz::RegisterLevelActions(*this);
|
Nz::RegisterLevelActions(*this);
|
||||||
Nz::RegisterEditorActions(*this);
|
Nz::RegisterEditorActions(*this);
|
||||||
|
Nz::RegisterCameraActions(*this);
|
||||||
Nz::RegisterLogActions(*this);
|
Nz::RegisterLogActions(*this);
|
||||||
|
|
||||||
Nz::Localization::OnLocaleInstalled.Connect([this](std::string_view locale) {
|
Nz::Localization::OnLocaleInstalled.Connect([this](std::string_view locale) {
|
||||||
|
|||||||
Reference in New Issue
Block a user