Compare commits

...

10 Commits

Author SHA1 Message Date
SweetId c8867197f0 update base level to show icon 2023-11-29 17:20:31 +05:30
SweetId dd7cdbdc8f renaming CameraSystem to ComponentsSystem
Now handles all editor components
2023-11-29 17:20:08 +05:30
SweetId bc18b5ef5d add icon to EditorNameComponent 2023-11-29 17:19:37 +05:30
SweetId fa4cc84a31 remove scrollbar from render window 2023-11-29 17:17:44 +05:30
SweetId bd4d1897f4 add filesystemcomponent and mount resource folder 2023-11-29 17:17:23 +05:30
SweetId ce17cbd269 pass argc and argv to Nz::Application 2023-11-28 17:17:19 +05:30
SweetId 77ae80b98e Add fill/keep aspect ratio modes in engine rendering 2023-11-25 11:22:07 +05:30
SweetId 736c6387dc Add Camera resolution change action 2023-11-24 18:57:06 +05:30
SweetId cfafff3077 3d image now fills the window 2023-11-24 17:39:16 +05:30
SweetId e396e26a7c add missing include 2023-11-24 17:38:55 +05:30
17 changed files with 422 additions and 115 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -14,6 +14,9 @@ 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_MENU_ASPECTRATIO;Aspect Ratio;Aspect Ratio
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
@ -26,4 +29,8 @@ LOC_EDITOR_WINDOW_LEVEL_TITLE;Level;Niveau
LOC_EDITOR_WINDOW_MAIN_TITLE;MainWindow;Fenêtre principale
LOC_EDITOR_WINDOW_OUTPUT_TITLE;Output;Sortie
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
1 ;en-US;fr-FR;
14 LOC_EDITOR_MENU_IMPORT;Import;Importer
15 LOC_EDITOR_MENU_TOOLS;Tools;Outils
16 LOC_EDITOR_MENU_LANGUAGE;Language;Langue
17 LOC_EDITOR_MENU_VIEW;View;Fenetre
18 LOC_EDITOR_MENU_RESOLUTION;Resolution;Résolution
19 LOC_EDITOR_MENU_ASPECTRATIO;Aspect Ratio;Aspect Ratio
20 LOC_EDITOR_ACTION_LEVEL_NEW_DESC;Create new level;Créé un nouveau niveau
21 LOC_EDITOR_ACTION_LEVEL_OPEN_DESC;Open a level;Ouvre un niveau
22 LOC_EDITOR_ACTION_LEVEL_SAVE_DESC;Save current level;Sauvegarde le niveau actuel
29 LOC_EDITOR_WINDOW_MAIN_TITLE;MainWindow;Fenêtre principale
30 LOC_EDITOR_WINDOW_OUTPUT_TITLE;Output;Sortie
31 LOC_EDITOR_POPUP_CREATE_LEVEL_TITLE;Warning;Attention
32 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?
33 LOC_EDITOR_CAMERA_KEEPASPECTRATIO_TITLE;Aspect Ratio;Aspect Ratio
34 LOC_EDITOR_CAMERA_KEEPASPECTRATIO_DESC;Keep Aspect Ratio;Garder l'aspect ratio
35 LOC_EDITOR_CAMERA_FILL_TITLE;Fill;Remplir
36 LOC_EDITOR_CAMERA_FILL_DESC;Fills the window;Remplis la fenetre

View File

@ -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;
};
}

View File

@ -7,6 +7,7 @@
#include <NazaraEditor/Core/Application/Level.hpp>
#include <NazaraEditor/Core/UI/PopupManager.hpp>
#include <NazaraEditor/Core/UI/Window.hpp>
#include <NazaraImgui/NazaraImgui.hpp>
#include <NazaraLocalization/Localization.hpp>
#include <NazaraEditor/Core/Core.hpp>
@ -35,7 +36,7 @@ namespace Nz
// Editor events
NazaraSignal(OnActionRegistered, const EditorAction::Properties&);
EditorBaseApplication();
EditorBaseApplication(int argc, char** argv);
virtual ~EditorBaseApplication();
static EditorBaseApplication* Instance();
@ -81,8 +82,15 @@ namespace Nz
inline Nz::Texture* GetEngineTexture() { 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:
void CreateEngineCamera();
static EditorBaseApplication* s_instance;
Nz::Window* m_window;
@ -98,5 +106,7 @@ namespace Nz
Nz::Level m_level;
entt::handle m_mainCamera;
StretchMode m_engineTextureStretchMode;
};
}

View File

@ -2,10 +2,19 @@
#include <NazaraEditor/Core/Config.hpp>
#include <Nazara/Core/Clock.hpp>
#include <NazaraUtils/Signal.hpp>
#include <filesystem>
#include <memory>
#include <string>
namespace Nz
{
class Billboard;
class NodeComponent;
class WorldInstance;
enum EditorEntityFlags : uint64_t
{
EditorEntityFlags_None = 0,
@ -24,15 +33,32 @@ namespace Nz
EditorNameComponent& operator=(const EditorNameComponent&) = delete;
EditorNameComponent& operator=(EditorNameComponent&&) = default;
void Update(Time elapsedTime, NodeComponent& node);
void SetName(const std::string& name) { m_name = 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; }
uint64_t GetFlags() const { return m_flags; }
NazaraSignal(OnIconChanged, EditorNameComponent*, const std::filesystem::path& );
private:
std::string m_name;
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;
};
}

View File

@ -15,4 +15,13 @@
#define NAZARAEDITOR_CORE_API
#endif
namespace Nz
{
enum StretchMode
{
Fill,
KeepAspectRatio
};
}
#endif // NAZARAEDITOR_CORE_CONFIG_HPP

View File

@ -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;
};
}

View File

@ -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;
};
}

View File

@ -8,7 +8,7 @@ namespace NzEditor
: public Nz::EditorBaseApplication
{
public:
Application();
Application(int argc, char** argv);
virtual bool NewLevel() override;
};

View File

@ -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);
}
}

View File

@ -1,9 +1,10 @@
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
#include <NazaraEditor/Core/Components/CameraComponent.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/AppFilesystemComponent.hpp>
#include <Nazara/Graphics/Components/CameraComponent.hpp>
#include <Nazara/Graphics/FramePipeline.hpp>
#include <Nazara/Graphics/RenderTexture.hpp>
@ -16,8 +17,10 @@ namespace Nz
{
EditorBaseApplication* EditorBaseApplication::s_instance = nullptr;
EditorBaseApplication::EditorBaseApplication()
: m_level(this)
EditorBaseApplication::EditorBaseApplication(int argc, char** argv)
: Application(argc, argv)
, m_level(this)
, m_engineTextureStretchMode(StretchMode::KeepAspectRatio)
{
NazaraAssert(s_instance == nullptr, "EditorBaseApplication already exists");
s_instance = this;
@ -26,9 +29,12 @@ namespace Nz
std::filesystem::path resourceDir = "assets/editor";
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
SetResourceFolder(resourceDir);
auto& windowing = AddComponent<Nz::AppWindowingComponent>();
auto& fs = AddComponent<Nz::AppFilesystemComponent>();
fs.Mount("editor:", resourceDir);
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_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<std::uint8_t> 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) {
@ -66,7 +57,7 @@ namespace Nz
ImGui::EnsureContextOnThisThread();
// 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);
AddUpdaterFunc(Interval{ Nz::Time::Milliseconds(16) }, [&](Nz::Time elapsed) {
@ -124,7 +115,7 @@ namespace Nz
if (bRes)
{
RenderSystem& system = m_level.GetEnttWorld()->AddSystem<RenderSystem>();
m_level.GetEnttWorld()->AddSystem<EditorCameraSystem>();
m_level.GetEnttWorld()->AddSystem<EditorComponentsSystem>();
system.AttachExternalSwapchain(*m_windowSwapchain);
system.GetFramePipeline().RegisterViewer(m_editorCamera.get(), 2);
@ -134,16 +125,57 @@ namespace Nz
auto& cmp = m_mainCamera.get<Nz::EditorNameComponent>();
cmp.SetFlags(EditorEntityFlags_Hidden);
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));
m_mainCamera.emplace<Nz::EditorCameraComponent>(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<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());
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -14,9 +14,12 @@
#include <NazaraLocalization/Localization.hpp>
#include <NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp>
namespace NzEditor
{
Application::Application()
Application::Application(int argc, char** argv)
: Nz::EditorBaseApplication(argc, argv)
{
RegisterWindow<NzEditor::MainWindow>();
RegisterWindow<NzEditor::AssetsWindow>();
@ -26,6 +29,7 @@ namespace NzEditor
Nz::RegisterLevelActions(*this);
Nz::RegisterEditorActions(*this);
Nz::RegisterCameraActions(*this);
Nz::RegisterLogActions(*this);
Nz::Localization::OnLocaleInstalled.Connect([this](std::string_view locale) {
@ -50,12 +54,17 @@ namespace NzEditor
Nz::DirectionalLight& light = lightComponent.AddLight<Nz::DirectionalLight>();
light.UpdateRotation(Nz::Quaternionf::LookAt(Nz::Vector3f(-1, 0, -1), Nz::Vector3f::Up()));
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));
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>();
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)));

View File

@ -18,10 +18,33 @@ namespace NzEditor
{
Nz::EditorMainWindow::OnRenderImgui();
if (ImGui::Begin("MainWindow"))
if (ImGui::Begin("MainWindow", nullptr, ImGuiWindowFlags_NoScrollbar))
{
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
auto cam = GetApplication()->GetMainCamera();

View File

@ -24,7 +24,7 @@ int WinMain(int argc, char* argv[])
Nz::EditorLogger logger;
NzEditor::Application app;
NzEditor::Application app(argc, argv);
app.SetLogger(logger);
ImGui::EnsureContextOnThisThread();