NoJobEngine 2.0.7
Loading...
Searching...
No Matches
EditorLayer.h
Go to the documentation of this file.
1
6#pragma once
7
9
10#include "Engine/Scene/Entity.h"
13
14#include <filesystem>
15#include <cstdint>
16#include <memory>
17#include <vector>
18#include <variant>
19#include <string>
20
21#include <glm/glm.hpp>
22
23struct GLFWwindow;
24
25namespace NoJob
26{
27 class Scene;
28 class Mesh;
29 class Material;
30
32 {
33 public:
34 void Init(GLFWwindow* window, Scene* scene);
35 void Shutdown();
36
37 void BeginFrame();
38 void Draw();
39 void EndFrame();
40
41 void SetSelectedEntity(Entity entity);
43 {
44 return m_SelectedEntity;
45 }
46
47 void SetScene(Scene* scene);
48
49 void SetViewportTexture(std::uint32_t textureID);
50
51 void SetCameraPreviewTexture(std::uint32_t textureID)
52 {
53 m_CameraPreviewTextureID = textureID;
54 }
55
56 bool ConsumePlayRequest();
58 bool ConsumeStopRequest();
59
63
65
66 // ------------------------------------------------------------
67 // AI / Navigation
68 // ------------------------------------------------------------
69
72
73 bool IsNavMeshVisible() const
74 {
75 return m_ShowNavMesh;
76 }
77
78 void SetRuntimeState(
79 bool playing,
80 bool paused);
81
83 const FramebufferSpecification& settings)
84 {
85 m_GraphicsSettings = settings;
86 }
87
90 {
91 return m_GraphicsSettings;
92 }
93
95 const glm::mat4& view,
96 const glm::mat4& projection);
97
99 std::shared_ptr<Mesh> mesh,
100 std::shared_ptr<Material> material);
101
102 std::uint32_t GetViewportWidth() const;
103 std::uint32_t GetViewportHeight() const;
104
105 bool IsViewportHovered() const
106 {
107 return m_ViewportHovered;
108 }
109
110 bool IsViewportFocused() const
111 {
112 return m_ViewportFocused;
113 }
114
115 private:
116 void DrawMainMenu();
117 void DrawPlayToolbar();
118 void DrawHierarchy();
119 void DrawEntityNode(Entity entity);
120 void DrawInspector();
121 void DrawViewport();
122 void DrawConsole();
123 void DrawProjectPanel();
124 void DrawGraphicsSettings();
125 void DrawRendererProfiler();
126 void DrawAIDebugger();
127 void DrawComponentTools();
128
129 std::string OpenInspectorAudioFileDialog();
130 std::string OpenInspectorTextureFileDialog();
131
132 void LogInspectorMessage(
133 const std::string& message);
134
135 bool HierarchyMatchesFilter(
136 Entity entity) const;
137
138 bool IsMultiSelected(
139 Entity entity) const;
140
141 void ClearMultiSelection();
142
143 Entity CreateEmptyEntity();
144 Entity CreateCubeEntity();
145
146 Entity CreateModelEntity(
147 const std::filesystem::path& modelPath);
148
149 void DeleteSelectedEntity();
150 void DuplicateSelectedEntity();
151
152 void PushUndoSnapshot(
153 std::unique_ptr<Scene> snapshot);
154
155 void CaptureUndoSnapshot();
156
157 void Undo();
158 void Redo();
159 void ClearRedoHistory();
160
161 private:
162 Scene* m_Scene = nullptr;
163
164 Entity m_SelectedEntity;
165
166 std::vector<std::uint32_t>
167 m_MultiSelection;
168
169 std::size_t
170 m_SelectedMaterialSlot = 0;
171
172 char m_HierarchySearch[128]{};
173
174 bool m_RenameSelectedRequested = false;
175 using ComponentClipboard =
176 std::variant<
177 std::monostate,
178 TransformComponent,
179 NativeScriptComponent,
180 RigidbodyComponent,
181 BoxColliderComponent,
182 SphereColliderComponent,
183 CapsuleColliderComponent,
184 CameraComponent,
185 DirectionalLightComponent,
186 PointLightComponent,
187 SpotLightComponent,
188 AnimatorComponent,
189 NavAgentComponent,
190 PerceptionComponent>;
191
192 ComponentClipboard
193 m_ComponentClipboard;
194
195 std::shared_ptr<Mesh>
196 m_DefaultCubeMesh;
197
198 std::shared_ptr<Material>
199 m_DefaultCubeMaterial;
200
201 std::uint32_t
202 m_ViewportTextureID = 0;
203
204 std::uint32_t
205 m_CameraPreviewTextureID = 0;
206
207 float m_ViewportWidth = 1280.0f;
208 float m_ViewportHeight = 720.0f;
209
210 bool m_ViewportHovered = false;
211 bool m_ViewportFocused = false;
212
213 glm::mat4 m_EditorView{ 1.0f };
214 glm::mat4 m_EditorProjection{ 1.0f };
215
216 int m_GizmoOperation = 0;
217
218 ProjectPanel m_ProjectPanel;
219
220 // ------------------------------------------------------------
221 // Runtime state
222 // ------------------------------------------------------------
223
224 bool m_IsPlaying = false;
225 bool m_IsPaused = false;
226
227 bool m_PlayRequested = false;
228 bool m_PauseRequested = false;
229 bool m_StopRequested = false;
230
231 // ------------------------------------------------------------
232 // Scene requests
233 // ------------------------------------------------------------
234
235 bool m_SaveSceneRequested = false;
236 bool m_SaveSceneAsRequested = false;
237 bool m_LoadSceneRequested = false;
238
239 bool m_GraphicsTestSceneRequested = false;
240
241 // ------------------------------------------------------------
242 // AI / Navigation
243 // ------------------------------------------------------------
244
245 bool m_BakeNavMeshRequested = false;
246 bool m_ClearNavMeshRequested = false;
247
248 bool m_ShowNavMesh = true;
249
250 // ------------------------------------------------------------
251 // Editor windows
252 // ------------------------------------------------------------
253
254 bool m_ShowGraphicsSettings = true;
255 bool m_ShowRendererProfiler = true;
256 bool m_ShowAIDebugger = true;
257 std::uint32_t m_AIDebugAgent = 0;
258 bool m_AIDebugOnlyActive = false;
259 bool m_AIDebugShowLastSeenMarker = false;
260
261 FramebufferSpecification
262 m_GraphicsSettings{};
263
264 // ------------------------------------------------------------
265 // Undo / Redo
266 // ------------------------------------------------------------
267
268 static constexpr std::size_t
269 MaxHistoryEntries = 64;
270
271 std::vector<std::unique_ptr<Scene>>
272 m_UndoHistory;
273
274 std::vector<std::unique_ptr<Scene>>
275 m_RedoHistory;
276
277 std::unique_ptr<Scene>
278 m_TransformEditSnapshot;
279
280 std::unique_ptr<Scene>
281 m_ScriptFieldEditSnapshot;
282
283 bool m_GizmoWasUsing = false;
284 };
285}
Components declarations for the Scenes and Native Scripting subsystem.
Entity declarations for the Scenes and Native Scripting subsystem.
Framebuffer declarations for the Rendering subsystem.
ProjectPanel declarations for the Asset Management subsystem.
void SetScene(Scene *scene)
void SetSelectedEntity(Entity entity)
void SetEditorCameraMatrices(const glm::mat4 &view, const glm::mat4 &projection)
bool ConsumeGraphicsTestSceneRequest()
Entity GetSelectedEntity() const
Definition EditorLayer.h:42
void SetRuntimeState(bool playing, bool paused)
bool IsViewportHovered() const
bool IsViewportFocused() const
void Init(GLFWwindow *window, Scene *scene)
bool ConsumeClearNavMeshRequest()
void SetDefaultCubeAssets(std::shared_ptr< Mesh > mesh, std::shared_ptr< Material > material)
void SetViewportTexture(std::uint32_t textureID)
bool IsNavMeshVisible() const
Definition EditorLayer.h:73
std::uint32_t GetViewportWidth() const
std::uint32_t GetViewportHeight() const
const FramebufferSpecification & GetGraphicsSettings() const
Definition EditorLayer.h:89
void SetGraphicsSettings(const FramebufferSpecification &settings)
Definition EditorLayer.h:82
void SetCameraPreviewTexture(std::uint32_t textureID)
Definition EditorLayer.h:51