Compare commits
10 Commits
ca83128851
...
c8867197f0
| Author | SHA1 | Date |
|---|---|---|
|
|
c8867197f0 | |
|
|
dd7cdbdc8f | |
|
|
bc18b5ef5d | |
|
|
fa4cc84a31 | |
|
|
bd4d1897f4 | |
|
|
ce17cbd269 | |
|
|
77ae80b98e | |
|
|
736c6387dc | |
|
|
cfafff3077 | |
|
|
e396e26a7c |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
|
|
@ -14,6 +14,9 @@ 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_MENU_ASPECTRATIO;Aspect Ratio;Aspect Ratio
|
||||||
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
|
||||||
|
|
@ -27,3 +30,7 @@ LOC_EDITOR_WINDOW_MAIN_TITLE;MainWindow;Fenêtre principale
|
||||||
LOC_EDITOR_WINDOW_OUTPUT_TITLE;Output;Sortie
|
LOC_EDITOR_WINDOW_OUTPUT_TITLE;Output;Sortie
|
||||||
LOC_EDITOR_POPUP_CREATE_LEVEL_TITLE;Warning;Attention
|
LOC_EDITOR_POPUP_CREATE_LEVEL_TITLE;Warning;Attention
|
||||||
LOC_EDITOR_POPUP_CREATE_LEVEL_DESC;Are you sure you want to create a new level?;Etes-vous sur de vouloir créer un nouveau niveau?
|
LOC_EDITOR_POPUP_CREATE_LEVEL_DESC;Are you sure you want to create a new level?;Etes-vous sur de vouloir créer un nouveau niveau?
|
||||||
|
LOC_EDITOR_CAMERA_KEEPASPECTRATIO_TITLE;Aspect Ratio;Aspect Ratio
|
||||||
|
LOC_EDITOR_CAMERA_KEEPASPECTRATIO_DESC;Keep Aspect Ratio;Garder l'aspect ratio
|
||||||
|
LOC_EDITOR_CAMERA_FILL_TITLE;Fill;Remplir
|
||||||
|
LOC_EDITOR_CAMERA_FILL_DESC;Fills the window;Remplis la fenetre
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#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;
|
||||||
|
};
|
||||||
|
|
||||||
|
class NAZARAEDITOR_CORE_API EditorAction_SetCameraStretchMode final
|
||||||
|
: public EditorAction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EditorAction_SetCameraStretchMode(const Properties& properties, StretchMode mode)
|
||||||
|
: EditorAction(properties)
|
||||||
|
, m_mode(mode)
|
||||||
|
{}
|
||||||
|
EditorAction_SetCameraStretchMode(const std::shared_ptr<Properties>& properties, StretchMode mode)
|
||||||
|
: EditorAction(properties)
|
||||||
|
, m_mode(mode)
|
||||||
|
{}
|
||||||
|
~EditorAction_SetCameraStretchMode() = default;
|
||||||
|
|
||||||
|
std::unique_ptr<EditorAction> Clone() const override { return std::make_unique<EditorAction_SetCameraStretchMode>(m_properties, m_mode); }
|
||||||
|
const std::string& GetName() const override { return m_properties->className; }
|
||||||
|
bool IsUndoRedoable() const override { return false; }
|
||||||
|
static const char* GetClassName() { return "EditorAction_SetCameraStretchMode"; }
|
||||||
|
|
||||||
|
void Execute() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
StretchMode m_mode;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <NazaraEditor/Core/Application/Level.hpp>
|
#include <NazaraEditor/Core/Application/Level.hpp>
|
||||||
#include <NazaraEditor/Core/UI/PopupManager.hpp>
|
#include <NazaraEditor/Core/UI/PopupManager.hpp>
|
||||||
#include <NazaraEditor/Core/UI/Window.hpp>
|
#include <NazaraEditor/Core/UI/Window.hpp>
|
||||||
|
#include <NazaraImgui/NazaraImgui.hpp>
|
||||||
#include <NazaraLocalization/Localization.hpp>
|
#include <NazaraLocalization/Localization.hpp>
|
||||||
|
|
||||||
#include <NazaraEditor/Core/Core.hpp>
|
#include <NazaraEditor/Core/Core.hpp>
|
||||||
|
|
@ -35,7 +36,7 @@ namespace Nz
|
||||||
// Editor events
|
// Editor events
|
||||||
NazaraSignal(OnActionRegistered, const EditorAction::Properties&);
|
NazaraSignal(OnActionRegistered, const EditorAction::Properties&);
|
||||||
|
|
||||||
EditorBaseApplication();
|
EditorBaseApplication(int argc, char** argv);
|
||||||
virtual ~EditorBaseApplication();
|
virtual ~EditorBaseApplication();
|
||||||
|
|
||||||
static EditorBaseApplication* Instance();
|
static EditorBaseApplication* Instance();
|
||||||
|
|
@ -82,7 +83,14 @@ 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(); }
|
||||||
|
|
||||||
|
inline StretchMode GetEngineTextureStretchMode() const { return m_engineTextureStretchMode; }
|
||||||
|
inline void SetEngineTextureStretchMode(StretchMode mode) { m_engineTextureStretchMode = mode; }
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
@ -98,5 +106,7 @@ namespace Nz
|
||||||
|
|
||||||
Nz::Level m_level;
|
Nz::Level m_level;
|
||||||
entt::handle m_mainCamera;
|
entt::handle m_mainCamera;
|
||||||
|
|
||||||
|
StretchMode m_engineTextureStretchMode;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,19 @@
|
||||||
|
|
||||||
#include <NazaraEditor/Core/Config.hpp>
|
#include <NazaraEditor/Core/Config.hpp>
|
||||||
|
|
||||||
|
#include <Nazara/Core/Clock.hpp>
|
||||||
|
#include <NazaraUtils/Signal.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
class Billboard;
|
||||||
|
class NodeComponent;
|
||||||
|
class WorldInstance;
|
||||||
|
|
||||||
enum EditorEntityFlags : uint64_t
|
enum EditorEntityFlags : uint64_t
|
||||||
{
|
{
|
||||||
EditorEntityFlags_None = 0,
|
EditorEntityFlags_None = 0,
|
||||||
|
|
@ -24,15 +33,32 @@ namespace Nz
|
||||||
EditorNameComponent& operator=(const EditorNameComponent&) = delete;
|
EditorNameComponent& operator=(const EditorNameComponent&) = delete;
|
||||||
EditorNameComponent& operator=(EditorNameComponent&&) = default;
|
EditorNameComponent& operator=(EditorNameComponent&&) = default;
|
||||||
|
|
||||||
|
void Update(Time elapsedTime, NodeComponent& node);
|
||||||
|
|
||||||
void SetName(const std::string& name) { m_name = name; }
|
void SetName(const std::string& name) { m_name = name; }
|
||||||
const std::string& GetName() const { return m_name; }
|
const std::string& GetName() const { return m_name; }
|
||||||
|
|
||||||
|
void SetIcon(const std::filesystem::path& path);
|
||||||
|
|
||||||
void SetFlags(const uint64_t flags) { m_flags = flags; }
|
void SetFlags(const uint64_t flags) { m_flags = flags; }
|
||||||
uint64_t GetFlags() const { return m_flags; }
|
uint64_t GetFlags() const { return m_flags; }
|
||||||
|
|
||||||
|
NazaraSignal(OnIconChanged, EditorNameComponent*, const std::filesystem::path& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
uint64_t m_flags;
|
uint64_t m_flags;
|
||||||
|
|
||||||
|
std::filesystem::path m_iconPath; // @TODO replace with asset
|
||||||
|
|
||||||
|
struct BillboardData
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
std::shared_ptr<Nz::WorldInstance> instance;
|
||||||
|
std::shared_ptr<Nz::Billboard> billboard;
|
||||||
|
};
|
||||||
|
std::optional<BillboardData> m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -15,4 +15,13 @@
|
||||||
#define NAZARAEDITOR_CORE_API
|
#define NAZARAEDITOR_CORE_API
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
enum StretchMode
|
||||||
|
{
|
||||||
|
Fill,
|
||||||
|
KeepAspectRatio
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // NAZARAEDITOR_CORE_CONFIG_HPP
|
#endif // NAZARAEDITOR_CORE_CONFIG_HPP
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <NazaraEditor/Core/Config.hpp>
|
|
||||||
|
|
||||||
#include <Nazara/Core/Time.hpp>
|
|
||||||
|
|
||||||
#include <entt/entt.hpp>
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
class NAZARAEDITOR_CORE_API EditorCameraSystem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static constexpr bool AllowConcurrent = false;
|
|
||||||
static constexpr Int64 ExecutionOrder = 1'001;
|
|
||||||
|
|
||||||
EditorCameraSystem(entt::registry& registry);
|
|
||||||
~EditorCameraSystem();
|
|
||||||
|
|
||||||
EditorCameraSystem(const EditorCameraSystem&) = delete;
|
|
||||||
EditorCameraSystem& operator=(const EditorCameraSystem&) = delete;
|
|
||||||
|
|
||||||
EditorCameraSystem(EditorCameraSystem&&) = delete;
|
|
||||||
EditorCameraSystem& operator=(EditorCameraSystem&&) = delete;
|
|
||||||
|
|
||||||
void Update(Time elapsedTime);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnCameraDestroy(entt::registry& registry, entt::entity entity);
|
|
||||||
|
|
||||||
entt::registry& m_registry;
|
|
||||||
|
|
||||||
entt::observer m_cameraConstructObserver;
|
|
||||||
entt::scoped_connection m_cameraDestroyConnection;
|
|
||||||
|
|
||||||
std::unordered_set<entt::entity> m_cameraEntities;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <NazaraEditor/Core/Config.hpp>
|
||||||
|
|
||||||
|
#include <Nazara/Core/Time.hpp>
|
||||||
|
|
||||||
|
#include <entt/entt.hpp>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class NAZARAEDITOR_CORE_API EditorComponentsSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr bool AllowConcurrent = false;
|
||||||
|
static constexpr Int64 ExecutionOrder = 1'001;
|
||||||
|
|
||||||
|
EditorComponentsSystem(entt::registry& registry);
|
||||||
|
~EditorComponentsSystem();
|
||||||
|
|
||||||
|
EditorComponentsSystem(const EditorComponentsSystem&) = delete;
|
||||||
|
EditorComponentsSystem& operator=(const EditorComponentsSystem&) = delete;
|
||||||
|
|
||||||
|
EditorComponentsSystem(EditorComponentsSystem&&) = delete;
|
||||||
|
EditorComponentsSystem& operator=(EditorComponentsSystem&&) = delete;
|
||||||
|
|
||||||
|
void Update(Time elapsedTime);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnCameraDestroy(entt::registry& registry, entt::entity entity);
|
||||||
|
void OnEntityDestroy(entt::registry& registry, entt::entity entity);
|
||||||
|
|
||||||
|
entt::registry& m_registry;
|
||||||
|
|
||||||
|
entt::observer m_cameraConstructObserver;
|
||||||
|
entt::observer m_entityConstructObserver;
|
||||||
|
entt::scoped_connection m_cameraDestroyConnection;
|
||||||
|
entt::scoped_connection m_entityDestroyConnection;
|
||||||
|
|
||||||
|
std::unordered_set<entt::entity> m_cameraEntities;
|
||||||
|
std::unordered_set<entt::entity> m_entities;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ namespace NzEditor
|
||||||
: public Nz::EditorBaseApplication
|
: public Nz::EditorBaseApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Application();
|
Application(int argc, char** argv);
|
||||||
|
|
||||||
virtual bool NewLevel() override;
|
virtual bool NewLevel() override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.RegisterAction<Nz::EditorAction_SetCameraStretchMode>({
|
||||||
|
.className = std::format("{}_{}", Nz::EditorAction_SetCameraSize::GetClassName(), "Fill"),
|
||||||
|
.description = "LOC_EDITOR_CAMERA_FILL_DESC",
|
||||||
|
.path = { "LOC_EDITOR_MENU_VIEW", "LOC_EDITOR_MENU_ASPECTRATIO", "LOC_EDITOR_CAMERA_FILL_TITLE" },
|
||||||
|
.category = "Tools",
|
||||||
|
}, StretchMode::Fill);
|
||||||
|
|
||||||
|
app.RegisterAction<Nz::EditorAction_SetCameraStretchMode>({
|
||||||
|
.className = std::format("{}_{}", Nz::EditorAction_SetCameraSize::GetClassName(), "AspectRatio"),
|
||||||
|
.description = "LOC_EDITOR_CAMERA_KEEPASPECTRATIO_DESC",
|
||||||
|
.path = { "LOC_EDITOR_MENU_VIEW", "LOC_EDITOR_MENU_ASPECTRATIO", "LOC_EDITOR_CAMERA_KEEPASPECTRATIO_TITLE" },
|
||||||
|
.category = "Tools",
|
||||||
|
}, StretchMode::KeepAspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorAction_SetCameraSize::Execute()
|
||||||
|
{
|
||||||
|
Nz::EditorBaseApplication::Instance()->CreateEngineTexture(m_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorAction_SetCameraStretchMode::Execute()
|
||||||
|
{
|
||||||
|
Nz::EditorBaseApplication::Instance()->SetEngineTextureStretchMode(m_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
#include <NazaraEditor/Core/Components/CameraComponent.hpp>
|
#include <NazaraEditor/Core/Components/CameraComponent.hpp>
|
||||||
#include <NazaraEditor/Core/Components/NameComponent.hpp>
|
#include <NazaraEditor/Core/Components/NameComponent.hpp>
|
||||||
#include <NazaraEditor/Core/Systems/CameraSystem.hpp>
|
#include <NazaraEditor/Core/Systems/ComponentsSystem.hpp>
|
||||||
|
|
||||||
#include <Nazara/Core/AppEntitySystemComponent.hpp>
|
#include <Nazara/Core/AppEntitySystemComponent.hpp>
|
||||||
|
#include <Nazara/Core/AppFilesystemComponent.hpp>
|
||||||
#include <Nazara/Graphics/Components/CameraComponent.hpp>
|
#include <Nazara/Graphics/Components/CameraComponent.hpp>
|
||||||
#include <Nazara/Graphics/FramePipeline.hpp>
|
#include <Nazara/Graphics/FramePipeline.hpp>
|
||||||
#include <Nazara/Graphics/RenderTexture.hpp>
|
#include <Nazara/Graphics/RenderTexture.hpp>
|
||||||
|
|
@ -16,8 +17,10 @@ namespace Nz
|
||||||
{
|
{
|
||||||
EditorBaseApplication* EditorBaseApplication::s_instance = nullptr;
|
EditorBaseApplication* EditorBaseApplication::s_instance = nullptr;
|
||||||
|
|
||||||
EditorBaseApplication::EditorBaseApplication()
|
EditorBaseApplication::EditorBaseApplication(int argc, char** argv)
|
||||||
: m_level(this)
|
: Application(argc, argv)
|
||||||
|
, m_level(this)
|
||||||
|
, m_engineTextureStretchMode(StretchMode::KeepAspectRatio)
|
||||||
{
|
{
|
||||||
NazaraAssert(s_instance == nullptr, "EditorBaseApplication already exists");
|
NazaraAssert(s_instance == nullptr, "EditorBaseApplication already exists");
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
@ -26,9 +29,12 @@ namespace Nz
|
||||||
std::filesystem::path resourceDir = "assets/editor";
|
std::filesystem::path resourceDir = "assets/editor";
|
||||||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
||||||
resourceDir = "../.." / resourceDir;
|
resourceDir = "../.." / resourceDir;
|
||||||
|
|
||||||
SetResourceFolder(resourceDir);
|
SetResourceFolder(resourceDir);
|
||||||
|
|
||||||
auto& windowing = AddComponent<Nz::AppWindowingComponent>();
|
auto& windowing = AddComponent<Nz::AppWindowingComponent>();
|
||||||
|
auto& fs = AddComponent<Nz::AppFilesystemComponent>();
|
||||||
|
fs.Mount("editor:", resourceDir);
|
||||||
|
|
||||||
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
|
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
|
||||||
|
|
||||||
|
|
@ -37,22 +43,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) {
|
||||||
|
|
@ -66,7 +57,7 @@ namespace Nz
|
||||||
ImGui::EnsureContextOnThisThread();
|
ImGui::EnsureContextOnThisThread();
|
||||||
|
|
||||||
// load the passes after Imgui is init
|
// load the passes after Imgui is init
|
||||||
auto passList = Nz::PipelinePassList::LoadFromFile(m_resourceFolder / "editor.passlist");
|
auto passList = fs.Load<Nz::PipelinePassList>("editor:/editor.passlist");
|
||||||
m_editorCamera = std::make_unique<Nz::Camera>(std::make_shared<RenderWindow>(*m_windowSwapchain), passList);
|
m_editorCamera = std::make_unique<Nz::Camera>(std::make_shared<RenderWindow>(*m_windowSwapchain), passList);
|
||||||
|
|
||||||
AddUpdaterFunc(Interval{ Nz::Time::Milliseconds(16) }, [&](Nz::Time elapsed) {
|
AddUpdaterFunc(Interval{ Nz::Time::Milliseconds(16) }, [&](Nz::Time elapsed) {
|
||||||
|
|
@ -124,7 +115,7 @@ namespace Nz
|
||||||
if (bRes)
|
if (bRes)
|
||||||
{
|
{
|
||||||
RenderSystem& system = m_level.GetEnttWorld()->AddSystem<RenderSystem>();
|
RenderSystem& system = m_level.GetEnttWorld()->AddSystem<RenderSystem>();
|
||||||
m_level.GetEnttWorld()->AddSystem<EditorCameraSystem>();
|
m_level.GetEnttWorld()->AddSystem<EditorComponentsSystem>();
|
||||||
|
|
||||||
system.AttachExternalSwapchain(*m_windowSwapchain);
|
system.AttachExternalSwapchain(*m_windowSwapchain);
|
||||||
system.GetFramePipeline().RegisterViewer(m_editorCamera.get(), 2);
|
system.GetFramePipeline().RegisterViewer(m_editorCamera.get(), 2);
|
||||||
|
|
@ -134,16 +125,57 @@ 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& fs = GetComponent<AppFilesystemComponent>();
|
||||||
|
auto passList = fs.Load<Nz::PipelinePassList>("editor:/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());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
#include <NazaraEditor/Core/Components/NameComponent.hpp>
|
||||||
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
|
|
||||||
|
#include <Nazara/Core/AppFilesystemComponent.hpp>
|
||||||
|
#include <Nazara/Graphics/Billboard.hpp>
|
||||||
|
#include <Nazara/Graphics/FramePipeline.hpp>
|
||||||
|
#include <Nazara/Graphics/MaterialInstance.hpp>
|
||||||
|
#include <Nazara/Graphics/Systems/RenderSystem.hpp>
|
||||||
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
void EditorNameComponent::Update(Time, NodeComponent& node)
|
||||||
|
{
|
||||||
|
if (!m_icon.has_value())
|
||||||
|
return;
|
||||||
|
m_icon.value().instance->UpdateWorldMatrix(node.GetTransformMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorNameComponent::SetIcon(const std::filesystem::path& path)
|
||||||
|
{
|
||||||
|
auto& level = EditorBaseApplication::Instance()->GetLevel();
|
||||||
|
auto& renderer = level.GetEnttWorld()->GetSystem<RenderSystem>();
|
||||||
|
|
||||||
|
if (m_icon.has_value())
|
||||||
|
{
|
||||||
|
renderer.GetFramePipeline().UnregisterRenderable(m_icon.value().index);
|
||||||
|
m_icon = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& fs = EditorBaseApplication::Instance()->GetComponent<Nz::AppFilesystemComponent>();
|
||||||
|
|
||||||
|
Nz::TextureParams params;
|
||||||
|
params.loadFormat = Nz::PixelFormat::RGBA8_SRGB;
|
||||||
|
std::shared_ptr<Nz::Texture> tex = fs.Load<Nz::Texture>(path.string(), params);
|
||||||
|
std::shared_ptr<Nz::MaterialInstance> mat = Nz::MaterialInstance::GetDefault(Nz::MaterialType::Basic, Nz::MaterialInstancePreset::Transparent)->Clone();
|
||||||
|
|
||||||
|
mat->SetTextureProperty("BaseColorMap", tex);
|
||||||
|
mat->SetValueProperty("Billboard", true);
|
||||||
|
|
||||||
|
m_icon = BillboardData{
|
||||||
|
.index = 0,
|
||||||
|
.instance = std::make_shared<Nz::WorldInstance>(),
|
||||||
|
.billboard = std::make_shared<Nz::Billboard>(mat, Nz::Vector2f(1.f, 1.f))
|
||||||
|
};
|
||||||
|
|
||||||
|
auto& icon = m_icon.value();
|
||||||
|
|
||||||
|
Nz::Recti scissorBox(-1, -1, -1, -1);
|
||||||
|
|
||||||
|
Nz::ElementRendererRegistry elementRegistry;
|
||||||
|
icon.index = renderer.GetFramePipeline().RegisterWorldInstance(icon.instance);
|
||||||
|
renderer.GetFramePipeline().RegisterRenderable(icon.index, Nz::FramePipeline::NoSkeletonInstance, icon.billboard.get(), 0xFFFFFFFF, scissorBox);
|
||||||
|
|
||||||
|
OnIconChanged(this, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
#include <NazaraEditor/Core/Systems/CameraSystem.hpp>
|
|
||||||
#include <NazaraEditor/Core/Components/CameraComponent.hpp>
|
|
||||||
|
|
||||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
|
||||||
|
|
||||||
namespace Nz
|
|
||||||
{
|
|
||||||
EditorCameraSystem::EditorCameraSystem(entt::registry& registry)
|
|
||||||
: m_registry(registry)
|
|
||||||
, m_cameraConstructObserver(registry, entt::collector.group<EditorCameraComponent, NodeComponent>())
|
|
||||||
{
|
|
||||||
m_cameraDestroyConnection = registry.on_destroy<EditorCameraComponent>().connect<&EditorCameraSystem::OnCameraDestroy>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorCameraSystem::~EditorCameraSystem()
|
|
||||||
{
|
|
||||||
m_cameraConstructObserver.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorCameraSystem::Update(Time elapsedTime)
|
|
||||||
{
|
|
||||||
m_cameraConstructObserver.each([&](entt::entity entity) {
|
|
||||||
m_cameraEntities.insert(entity);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (auto entity : m_cameraEntities)
|
|
||||||
{
|
|
||||||
EditorCameraComponent& camera = m_registry.get<EditorCameraComponent>(entity);
|
|
||||||
NodeComponent& transform = m_registry.get<NodeComponent>(entity);
|
|
||||||
|
|
||||||
camera.Update(elapsedTime, transform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorCameraSystem::OnCameraDestroy(entt::registry& registry, entt::entity entity)
|
|
||||||
{
|
|
||||||
m_cameraEntities.erase(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
#include <NazaraEditor/Core/Systems/ComponentsSystem.hpp>
|
||||||
|
#include <NazaraEditor/Core/Components/CameraComponent.hpp>
|
||||||
|
#include <NazaraEditor/Core/Components/NameComponent.hpp>
|
||||||
|
|
||||||
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
EditorComponentsSystem::EditorComponentsSystem(entt::registry& registry)
|
||||||
|
: m_registry(registry)
|
||||||
|
, m_cameraConstructObserver(registry, entt::collector.group<EditorCameraComponent, NodeComponent>())
|
||||||
|
, m_entityConstructObserver(registry, entt::collector.group<EditorNameComponent, NodeComponent>())
|
||||||
|
{
|
||||||
|
m_cameraDestroyConnection = registry.on_destroy<EditorCameraComponent>().connect<&EditorComponentsSystem::OnCameraDestroy>(this);
|
||||||
|
m_entityDestroyConnection = registry.on_destroy<EditorNameComponent>().connect<&EditorComponentsSystem::OnEntityDestroy>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorComponentsSystem::~EditorComponentsSystem()
|
||||||
|
{
|
||||||
|
m_cameraConstructObserver.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorComponentsSystem::Update(Time elapsedTime)
|
||||||
|
{
|
||||||
|
m_cameraConstructObserver.each([&](entt::entity entity) {
|
||||||
|
m_cameraEntities.insert(entity);
|
||||||
|
});
|
||||||
|
|
||||||
|
m_entityConstructObserver.each([&](entt::entity entity) {
|
||||||
|
m_entities.insert(entity);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (auto entity : m_cameraEntities)
|
||||||
|
{
|
||||||
|
EditorCameraComponent& camera = m_registry.get<EditorCameraComponent>(entity);
|
||||||
|
NodeComponent& transform = m_registry.get<NodeComponent>(entity);
|
||||||
|
|
||||||
|
camera.Update(elapsedTime, transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (auto entity : m_entities)
|
||||||
|
{
|
||||||
|
EditorNameComponent& component = m_registry.get<EditorNameComponent>(entity);
|
||||||
|
NodeComponent& transform = m_registry.get<NodeComponent>(entity);
|
||||||
|
|
||||||
|
component.Update(elapsedTime, transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorComponentsSystem::OnCameraDestroy(entt::registry& registry, entt::entity entity)
|
||||||
|
{
|
||||||
|
m_cameraEntities.erase(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorComponentsSystem::OnEntityDestroy(entt::registry& registry, entt::entity entity)
|
||||||
|
{
|
||||||
|
m_entities.erase(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,9 +14,12 @@
|
||||||
|
|
||||||
#include <NazaraLocalization/Localization.hpp>
|
#include <NazaraLocalization/Localization.hpp>
|
||||||
|
|
||||||
|
#include <NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp>
|
||||||
|
|
||||||
namespace NzEditor
|
namespace NzEditor
|
||||||
{
|
{
|
||||||
Application::Application()
|
Application::Application(int argc, char** argv)
|
||||||
|
: Nz::EditorBaseApplication(argc, argv)
|
||||||
{
|
{
|
||||||
RegisterWindow<NzEditor::MainWindow>();
|
RegisterWindow<NzEditor::MainWindow>();
|
||||||
RegisterWindow<NzEditor::AssetsWindow>();
|
RegisterWindow<NzEditor::AssetsWindow>();
|
||||||
|
|
@ -26,6 +29,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) {
|
||||||
|
|
@ -50,12 +54,17 @@ namespace NzEditor
|
||||||
Nz::DirectionalLight& light = lightComponent.AddLight<Nz::DirectionalLight>();
|
Nz::DirectionalLight& light = lightComponent.AddLight<Nz::DirectionalLight>();
|
||||||
light.UpdateRotation(Nz::Quaternionf::LookAt(Nz::Vector3f(-1, 0, -1), Nz::Vector3f::Up()));
|
light.UpdateRotation(Nz::Quaternionf::LookAt(Nz::Vector3f(-1, 0, -1), Nz::Vector3f::Up()));
|
||||||
light.EnableShadowCasting(true);
|
light.EnableShadowCasting(true);
|
||||||
|
|
||||||
|
{
|
||||||
|
auto& cmp = directional.get<Nz::EditorNameComponent>();
|
||||||
|
cmp.SetIcon("editor:/icons/light.png");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 1; ++i)
|
for (int i = 0; i < 5; ++i)
|
||||||
{
|
{
|
||||||
auto cube = CreateEntity(std::format("Cube_{}", i + 1));
|
auto cube = CreateEntity(std::format("Cube_{}", i + 1));
|
||||||
cube.get<Nz::NodeComponent>().SetPosition(Nz::Vector3f(i * 2, 0, 0));
|
cube.get<Nz::NodeComponent>().SetPosition(Nz::Vector3f(i * 2, 0, i + 1));
|
||||||
Nz::GraphicsComponent& graphicsComponent = cube.emplace<Nz::GraphicsComponent>();
|
Nz::GraphicsComponent& graphicsComponent = cube.emplace<Nz::GraphicsComponent>();
|
||||||
|
|
||||||
std::shared_ptr<Nz::GraphicalMesh> boxMesh = Nz::GraphicalMesh::Build(Nz::Primitive::Box(Nz::Vector3f(1.f), Nz::Vector3ui::Zero(), Nz::Matrix4f::Scale(Nz::Vector3f(1.f)), Nz::Rectf(0.f, 0.f, 2.f, 2.f)));
|
std::shared_ptr<Nz::GraphicalMesh> boxMesh = Nz::GraphicalMesh::Build(Nz::Primitive::Box(Nz::Vector3f(1.f), Nz::Vector3ui::Zero(), Nz::Matrix4f::Scale(Nz::Vector3f(1.f)), Nz::Rectf(0.f, 0.f, 2.f, 2.f)));
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,33 @@ namespace NzEditor
|
||||||
{
|
{
|
||||||
Nz::EditorMainWindow::OnRenderImgui();
|
Nz::EditorMainWindow::OnRenderImgui();
|
||||||
|
|
||||||
if (ImGui::Begin("MainWindow"))
|
if (ImGui::Begin("MainWindow", nullptr, ImGuiWindowFlags_NoScrollbar))
|
||||||
{
|
{
|
||||||
auto pos = ImGui::GetCursorPos();
|
auto pos = ImGui::GetCursorPos();
|
||||||
ImGui::Image(GetApplication()->GetEngineTexture());
|
auto size = ImGui::GetContentRegionAvail();
|
||||||
|
auto stretch = GetApplication()->GetEngineTextureStretchMode();
|
||||||
|
|
||||||
|
auto texSize = GetApplication()->GetEngineTexture()->GetSize();
|
||||||
|
|
||||||
|
if (stretch == Nz::StretchMode::KeepAspectRatio)
|
||||||
|
{
|
||||||
|
if (texSize.x > texSize.y)
|
||||||
|
{
|
||||||
|
float x = size.x;
|
||||||
|
float y = texSize.y * size.x / texSize.x;
|
||||||
|
ImGui::Image(GetApplication()->GetEngineTexture(), Nz::Vector2f{ x, y });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float x = texSize.x * size.y / texSize.y;
|
||||||
|
float y = size.y;
|
||||||
|
ImGui::Image(GetApplication()->GetEngineTexture(), Nz::Vector2f{ x, y });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::Image(GetApplication()->GetEngineTexture(), Nz::Vector2f{ size.x, size.y });
|
||||||
|
}
|
||||||
ImGui::SetCursorPos(pos); // everything else will be drawn on top of the texture
|
ImGui::SetCursorPos(pos); // everything else will be drawn on top of the texture
|
||||||
|
|
||||||
auto cam = GetApplication()->GetMainCamera();
|
auto cam = GetApplication()->GetMainCamera();
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ int WinMain(int argc, char* argv[])
|
||||||
|
|
||||||
Nz::EditorLogger logger;
|
Nz::EditorLogger logger;
|
||||||
|
|
||||||
NzEditor::Application app;
|
NzEditor::Application app(argc, argv);
|
||||||
app.SetLogger(logger);
|
app.SetLogger(logger);
|
||||||
|
|
||||||
ImGui::EnsureContextOnThisThread();
|
ImGui::EnsureContextOnThisThread();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue