Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::EditorLayer Class Reference

#include <EditorLayer.h>

Inheritance diagram for Muto::EditorLayer:
Muto::Layer

Public Member Functions

 EditorLayer ()
 
virtual void OnAttach () override
 Called when the layer is attached to the application.
 
virtual void OnDetach () override
 Called when the layer is detached from the application.
 
virtual void OnEvent (Event &e) override
 Called when an event is dispatched to the layer.
 
virtual void OnImGuiRender () override
 Called when the layer should render its ImGui components.
 
virtual void OnUpdate (Timestep ts) override
 Called every frame to update the layer with the given timestep.
 
virtual ~EditorLayer ()=default
 
- Public Member Functions inherited from Muto::Layer
const std::string & GetName () const
 Retrieves the name of the layer for debugging purposes.
 
 Layer (const std::string &name="Layer")
 Constructs a Layer with an optional name for debugging purposes.
 
virtual void OnRender ()
 Called when the layer should render its contents.
 
virtual ~Layer ()
 

Private Types

enum class  SceneState { Edit = 0 , Play = 1 , Simulate = 2 }
 

Private Member Functions

void NewScene ()
 
bool OnKeyPressed (KeyPressedEvent &e)
 
void OpenScene ()
 
void ResetScene ()
 
void SaveSceneAs ()
 

Private Attributes

float lastFrameTime = 0.0f
 
Ref< Scene > m_ActiveScene
 
glm::vec4 m_BackgroundColor = { 0.1f, 0.1f, 0.1f, 1.0f }
 
OrthographicCameraController m_CameraController
 
Entity m_CameraEntity
 
Ref< Texture2D > m_CheckerboardTexture
 
glm::vec4 m_ClearColor = { 0.1f, 0.3f, 0.3f, 1.0f }
 
EditorCamera m_EditorCamera
 
Ref< Scene > m_EditorScene
 
Entity m_FireEntity
 
Ref< Shader > m_FlatColorShader
 
Ref< Framebuffer > m_Framebuffer
 
int m_GizmoType = -1
 
int m_ParticleEmitCount = 100
 
ParticleProps m_ParticleProps
 
ParticleSystem m_ParticleSystem
 
bool m_PrimaryCamera = true
 
float m_RotationSnap = 45.0f
 
float m_ScaleSnap = 0.5f
 
SceneHierarchyPanel m_SceneHierarchyPanel
 
SceneState m_SceneState = SceneState::Edit
 
Entity m_SmokeEntity
 
glm::vec4 m_SpecialQuadColor = { 0.9f, 0.2f, 0.8f, 1.0f }
 
float m_specialQuadRotation = 0.5f
 
Ref< Texture2D > m_SpriteSheetCrystals
 
Ref< Texture2D > m_SpriteSheetCursedLands
 
Ref< Texture2D > m_SpriteSheetFire
 
Ref< Texture2D > m_SpriteSheetRocks
 
Ref< Texture2D > m_SpriteSheetSmoke
 
Ref< Texture2D > m_SpriteSheetTown
 
glm::vec4 m_SquareColor = { 0.2f, 0.3f, 0.8f, 1.0f }
 
float m_squareRotation = 25.0f
 
Ref< VertexArray > m_SquareVA
 
Ref< SubTexture2D > m_SubTextureFire
 
Ref< SubTexture2D > m_SubTextureSmoke
 
Ref< SubTexture2D > m_SubTextureTown
 
float m_textureScale = 1.0f
 
glm::vec4 m_TextureTintColor1 = { 1.0f, 1.0f, 1.0f, 1.0f }
 
glm::vec4 m_TextureTintColor2 = { 1.0f, 1.0f, 1.0f, 1.0f }
 
float m_TranslationSnap = 0.5f
 
bool m_UseSpecialQuadColor = false
 
glm::vec2 m_ViewportBounds [2] = { {0,0}, {0,0} }
 
bool m_ViewportFocused = false
 
bool m_ViewportHovered = false
 
glm::vec2 m_ViewportSize = {0,0}
 
std::unordered_map< char, Ref< SubTexture2D > > s_TextureMap
 
bool scene1 = false
 
bool scene2 = false
 
bool scene3 = false
 
bool scene4 = false
 
bool useEntityScene = true
 

Additional Inherited Members

- Protected Attributes inherited from Muto::Layer
std::string m_DebugName
 The name of the layer assigned at creation, used for debugging.
 

Member Enumeration Documentation

◆ SceneState

Enumerator
Edit 
Play 
Simulate 

Constructor & Destructor Documentation

◆ EditorLayer()

Muto::EditorLayer::EditorLayer ( )
39 : Layer("Sandbox2D"), m_CameraController(1280.0f / 720.0f, true)
40 {
42 }
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
OrthographicCameraController m_CameraController
Definition EditorLayer.h:52
Layer(const std::string &name="Layer")
Constructs a Layer with an optional name for debugging purposes.
Definition Layer.cpp:6

References EditorLayer().

Referenced by EditorLayer(), Muto::Mutare::Mutare(), SandboxApp::SandboxApp(), and SandboxApp::SandboxApp().

◆ ~EditorLayer()

virtual Muto::EditorLayer::~EditorLayer ( )
virtualdefault

Member Function Documentation

◆ NewScene()

void Muto::EditorLayer::NewScene ( )
private
533 {
537 }
Ref< Scene > m_ActiveScene
Definition EditorLayer.h:34
SceneHierarchyPanel m_SceneHierarchyPanel
Definition EditorLayer.h:32
glm::vec2 m_ViewportSize
Definition EditorLayer.h:44
void SetContext(const Ref< Scene > &context)
Definition SceneHierarchyPanel.cpp:22
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

Referenced by OnImGuiRender(), and OnKeyPressed().

◆ OnAttach()

void Muto::EditorLayer::OnAttach ( )
overridevirtual

Called when the layer is attached to the application.

TODO: move to resource manager TODO: fix pathing

TODO: Get an automatic path to resource that is NOT hardcoded

TODO: move to resource manager TODO: fix pathing

TODO: Get an automatic path to resource that is NOT hardcoded

Reimplemented from Muto::Layer.

47 {
49
50 // Texture / SubTexture setup
51 {
54 m_CheckerboardTexture = Texture2D::Create("Muto/src/Editor/assets/textures/Checkerboard.png");
55 m_SpriteSheetFire = Texture2D::Create("Muto/src/Editor/assets/textures/sheets/fire_01.png");
56 m_SpriteSheetSmoke = Texture2D::Create("Muto/src/Editor/assets/textures/sheets/fire_02.png");
57 m_SpriteSheetTown = Texture2D::Create("Muto/src/Editor/assets/textures/sheets/town_tilesheet.png");
58 m_SpriteSheetCrystals = Texture2D::Create("Muto/src/Editor/assets/textures/sheets/craftpix/Crystals/Crystals.png");
59 m_SpriteSheetRocks = Texture2D::Create("Muto/src/Editor/assets/textures/sheets/craftpix/Rocks/Rocks_source.png");
60 m_SpriteSheetCursedLands = Texture2D::Create("Muto/src/Editor/assets/textures/sheets/craftpix/CursedLand/Tiled_files/Objects.png");
61
64 m_SubTextureTown = SubTexture2D::CreateFromCoords(m_SpriteSheetTown, { 4.25, 0.75 }, { 64, 64 }, { 1, 1 });
66 s_TextureMap['G'] = SubTexture2D::CreateFromCoords(m_SpriteSheetTown, { 4.25, 0.75 }, { 64, 64 }, { 1, 1 });
67 s_TextureMap['C'] = SubTexture2D::CreateFromCoords(m_SpriteSheetCrystals, { 0, 1.25 }, { 64, 64 }, { 1, 1 });
68 s_TextureMap['R'] = SubTexture2D::CreateFromCoords(m_SpriteSheetRocks, { 0, 3.75 }, { 64, 64 }, { 1, 1 });
69 s_TextureMap['P'] = SubTexture2D::CreateFromCoords(m_SpriteSheetCursedLands, { 0, 1.875 }, { 128, 128 }, { 1, 1 });
70 }
71
72
73 // Particle setup
74 {
75 m_ParticleProps.Position = { 0.0f, 0.0f, 0.0f };
76 m_ParticleProps.Velocity = { 0.0f, 0.0f, 0.0f };
77 m_ParticleProps.VelocityVariation = { 1.0f, 1.0f, 0.0f };
78 m_ParticleProps.ColorBegin = { 1.0f, 0.5f, 0.2f, 1.0f };
79 m_ParticleProps.ColorEnd = { 0.2f, 0.3f, 0.8f, 1.0f };
85 m_ParticleSystem = ParticleSystem(10000);
87 }
88
89 // Framebuffer/Viewport setup
90 {
91 FramebufferSpecification fbSpec;
92 fbSpec.Width = 1280;
93 fbSpec.Height = 720;
95 }
96
97 // Scene setup
98 {
99 //m_CameraController.SetZoomLevel(5.5f);
101
102#if 0
103 m_CameraEntity = m_ActiveScene->CreateEntity("Primary Camera Entity");
104
105 auto& pCam = m_CameraEntity.AddComponent<CameraComponent>();
106 pCam.Primary = true;
107 pCam.Camera.SetPerspective(glm::radians(45.0f), 0.1f, 1000.0f);
108 auto& pos = m_CameraEntity.GetComponent<TransformComponent>().Translation;
109 pos.x += 1.25f;
110 pos.z += 5.0f;
111
112 auto fbSpec = m_Framebuffer->GetSpecification();
113 m_ActiveScene->OnViewportResize(fbSpec.Width, fbSpec.Height);
114
115 // Animation 1
116 {
117 auto square = m_ActiveScene->CreateEntity("Fire Animation");
118 auto& transform = square.GetComponent<TransformComponent>();
119 transform.Translation = (glm::vec3(-0.5f, 0.0f, -1.5f));
120
121 square.AddComponent<SpriteRendererComponent>(glm::vec4{ 0.8f, 0.8f, 0.2f, 1.0f });
122 std::vector<Ref<SubTexture2D>> fireFrames;
123 for (int x = 0; x < 63; x++)
124 {
125 for (int y = 0; y < 2; y++)
126 {
127 fireFrames.push_back(SubTexture2D::CreateFromCoords(m_SpriteSheetFire, { (float)y, (float)x }, { 128, 128 }));
128 }
129 }
130 TextureAnimationComponent texAnim(fireFrames, 0.05f);
131 square.AddComponent<TextureAnimationComponent>(texAnim);
133 }
134
135 // Animation 2
136 {
137 auto square = m_ActiveScene->CreateEntity("Smoke Animation");
138 auto& transform = square.GetComponent<TransformComponent>();
139 // adjust the position of the square entity
140 transform.Translation = (glm::vec3(0.5f, 0.0f, 1.5f));
141
142 square.AddComponent<SpriteRendererComponent>(glm::vec4{ 0.8f, 0.8f, 0.2f, 1.0f });
143 std::vector<Ref<SubTexture2D>> smokeFrames;
144 for (int x = 0; x < 63; x++)
145 {
146 for (int y = 0; y < 2; y++)
147 {
148 smokeFrames.push_back(SubTexture2D::CreateFromCoords(m_SpriteSheetSmoke, { (float)y, (float)x }, { 128, 128 }));
149 }
150
151 }
152 TextureAnimationComponent texAnim(smokeFrames, 0.05f);
153 square.AddComponent<TextureAnimationComponent>(texAnim);
155 }
156
157 auto quadEntity = m_ActiveScene->CreateEntity("Quad Entity");
158 quadEntity.AddComponent<SpriteRendererComponent>(glm::vec4{ 0.2f, 0.3f, 0.8f, 1.0f });
159 quadEntity.GetComponent<TransformComponent>().Scale = { 0.5f, 0.5f, 1.0f };
160 quadEntity.GetComponent<TransformComponent>().Translation = { 1.5f, 0.0f, 0.0f };
161
162
163 class CameraController : public ScriptableEntity {
164 public:
165 void OnCreate()
166 {
167 GetComponent<TransformComponent>().Translation = (glm::vec3(Random::RangeF1(-3.0f, 3.0f), Random::RangeF1(-3.0f, 3.0f), 0.0f));
168
169 }
170
171 void OnDestroy()
172 {
173
174 }
175
176 void OnUpdate(Timestep ts)
177 {
178 auto& transform = GetComponent<TransformComponent>().GetTransform();
179 float speed = 5.0f;
180
181
182 if (Input::IsKeyPressed(VZ_KEY_A))
183 transform[3][0] -= speed * ts;
184
185 if (Input::IsKeyPressed(VZ_KEY_D))
186 transform[3][0] += speed * ts;
187
188 if (Input::IsKeyPressed(VZ_KEY_W))
189 transform[3][1] += speed * ts;
190
191 if (Input::IsKeyPressed(VZ_KEY_S))
192 transform[3][1] -= speed * ts;
193 }
194
195 };
196
197 m_CameraEntity.AddComponent<NativeScriptComponent>().Bind<CameraController>();
198 m_SecondaryCameraEntity.AddComponent<NativeScriptComponent>().Bind<CameraController>();
199
200#endif
201
203
204 SceneSerializer serializer(m_ActiveScene);
205
207
211
212 bool valid = serializer.Deserialize(loadedScene);
213 if (!valid) {
214 MU_CORE_ERROR("Failed to load default scene: " + loadedScene);
215 MU_CORE_ERROR("Attempted Scene: " + std::string(MU_EDITOR_DEFAULT_SCENE));
216 MU_CORE_ERROR("Current Working Directory: " + FileSystem::GetCurrentWorkingDirectory());
217 MU_CORE_ERROR("Absolute Path Attempted: " + FileSystem::GetAbsolutePath(loadedScene));
218 MU_CORE_ERROR("Error loading the scene, please check the paths and file availability.");
219 }
220 else {
221 MU_CORE_INFO("Successfully loaded the default scene: " + loadedScene);
222 }
223 }
224 m_EditorCamera = EditorCamera(30.0f, 1.778f, 0.1f, 1000.0f);
225 }
226
227
228 }
#define MU_CORE_ERROR(...)
error: indicates an error that has occurred
Definition Log.h:42
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
ParticleProps m_ParticleProps
Definition EditorLayer.h:86
Ref< SubTexture2D > m_SubTextureSmoke
Definition EditorLayer.h:70
EditorCamera m_EditorCamera
Definition EditorLayer.h:78
Entity m_CameraEntity
Definition EditorLayer.h:47
Ref< Framebuffer > m_Framebuffer
Definition EditorLayer.h:76
Entity m_FireEntity
Definition EditorLayer.h:55
Ref< Texture2D > m_SpriteSheetFire
Definition EditorLayer.h:62
Ref< SubTexture2D > m_SubTextureFire
Definition EditorLayer.h:69
std::unordered_map< char, Ref< SubTexture2D > > s_TextureMap
Definition EditorLayer.h:100
ParticleSystem m_ParticleSystem
Definition EditorLayer.h:85
Ref< Texture2D > m_SpriteSheetTown
Definition EditorLayer.h:64
Ref< Texture2D > m_CheckerboardTexture
Definition EditorLayer.h:60
Ref< Texture2D > m_SpriteSheetRocks
Definition EditorLayer.h:66
Ref< Texture2D > m_SpriteSheetSmoke
Definition EditorLayer.h:63
Entity m_SmokeEntity
Definition EditorLayer.h:55
Ref< SubTexture2D > m_SubTextureTown
Definition EditorLayer.h:71
Ref< Texture2D > m_SpriteSheetCursedLands
Definition EditorLayer.h:67
Ref< Texture2D > m_SpriteSheetCrystals
Definition EditorLayer.h:65
T & GetComponent()
Retrieves a reference to the component of type T attached to the entity if it exists....
Definition Entity.h:73
T & AddComponent(Args &&... args)
Adds a component of type T to the entity with the provided arguments Otherwise, asserts if the entity...
Definition Entity.h:48
static void Initialize()
Definition FileSystem.cpp:16
static std::string GetAbsolutePath(const std::string &relativePath)
Definition FileSystem.cpp:38
static std::string GetCurrentWorkingDirectory()
Definition FileSystem.cpp:33
static Ref< Framebuffer > Create(const FramebufferSpecification &spec)
Creates a framebuffer with the given specification.
Definition Framebuffer.cpp:9
void SetParticleProps(const ParticleProps &particleProps)
Definition ParticleSystem.h:53
static Ref< SubTexture2D > CreateFromCoords(const Ref< Texture2D > &texture, const glm::vec2 &coords, const glm::vec2 &cellSize, const glm::vec2 &spriteSize={1, 1})
Creates a SubTexture2D from a grid of cells within the given texture.
Definition SubTexture2D.cpp:17
static Ref< Texture2D > Create(uint32_t width, uint32_t height)
Definition Texture.cpp:10
float SizeBegin
Definition ParticleSystem.h:19
glm::vec3 Position
Definition ParticleSystem.h:13
float RotationVariation
Definition ParticleSystem.h:23
float Lifetime
Definition ParticleSystem.h:24
glm::vec4 ColorEnd
Definition ParticleSystem.h:18
glm::vec3 VelocityVariation
Definition ParticleSystem.h:16
glm::vec4 ColorBegin
Definition ParticleSystem.h:17
float Rotation
Definition ParticleSystem.h:22
glm::vec3 Velocity
Definition ParticleSystem.h:15
float SizeEnd
Definition ParticleSystem.h:20

References Muto::SceneSerializer::Deserialize(), Muto::FileSystem::GetAbsolutePath(), Muto::FileSystem::GetCurrentWorkingDirectory(), Muto::FramebufferSpecification::Height, Muto::FileSystem::Initialize(), and Muto::FramebufferSpecification::Width.

◆ OnDetach()

void Muto::EditorLayer::OnDetach ( )
overridevirtual

Called when the layer is detached from the application.

Reimplemented from Muto::Layer.

231 {
233 }

◆ OnEvent()

void Muto::EditorLayer::OnEvent ( Event &  event)
overridevirtual

Called when an event is dispatched to the layer.

Parameters
eventThe event being dispatched.

Reimplemented from Muto::Layer.

469 {
473 }
474
475 EventDispatcher dispatcher(e);
476 dispatcher.Dispatch<KeyPressedEvent>(MU_BIND_EVENT_FN(EditorLayer::OnKeyPressed));
477
478 }
#define MU_BIND_EVENT_FN(fn)
Binds a member function as an event handler.
Definition Defines_Macros.h:17
void OnEvent(Event &e)
Definition EditorCamera.cpp:65
bool OnKeyPressed(KeyPressedEvent &e)
Definition EditorLayer.cpp:480
SceneState m_SceneState
Definition EditorLayer.h:41
void OnEvent(Event &e)
Definition OrthographicCameraController.cpp:47

References Edit, Muto::EventDispatcher::EventDispatcher(), m_SceneState, and OnKeyPressed().

◆ OnImGuiRender()

void Muto::EditorLayer::OnImGuiRender ( )
overridevirtual

Called when the layer should render its ImGui components.

Reimplemented from Muto::Layer.

282 {
284
285 static bool dockspaceOpen = true;
286 static bool opt_fullscreen = true;
287 static bool opt_padding = false;
289
290 // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
291 // because it would be confusing to have two docking targets within each others.
293 if (opt_fullscreen)
294 {
295 const ImGuiViewport* viewport = ImGui::GetMainViewport();
296 ImGui::SetNextWindowPos(viewport->WorkPos);
297 ImGui::SetNextWindowSize(viewport->WorkSize);
298 ImGui::SetNextWindowViewport(viewport->ID);
299 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
300 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
303 }
304
305 // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background
306 // and handle the pass-thru hole, so we ask Begin() to not render a background.
309
310 // Important: note that we proceed even if Begin() returns false (aka window is collapsed).
311 // This is because we want to keep our DockSpace() active. If a DockSpace() is inactive,
312 // all active windows docked into it will lose their parent and become undocked.
313 // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise
314 // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible.
315 if (!opt_padding)
316 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
317 ImGui::Begin("DockSpace Demo", &dockspaceOpen, window_flags);
318 if (!opt_padding)
319 ImGui::PopStyleVar();
320
321 if (opt_fullscreen)
322 ImGui::PopStyleVar(2);
323
324 // Submit the DockSpace
325 ImGuiIO& io = ImGui::GetIO();
326 ImGuiStyle& style = ImGui::GetStyle();
327 float minWinSize = style.WindowMinSize.x = 370.0f;
328
329 if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
330 {
331 ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
332 ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
333 }
334
335 style.WindowMinSize.x = minWinSize;
336
337 if (ImGui::BeginMenuBar())
338 {
339 if (ImGui::BeginMenu("File"))
340 {
341 // Disabling fullscreen would allow the window to be moved to the front of other windows,
342 // which we can't undo at the moment without finer window depth/z control.
343
344 if (ImGui::MenuItem("New", "Ctrl+N"))
345 NewScene();
346
347
348 if (ImGui::MenuItem("Open..", "Ctrl+O"))
349 OpenScene();
350
351
352 if (ImGui::MenuItem("Save As..", "Ctrl+Shift+S"))
353 SaveSceneAs();
354
355
356 if (ImGui::MenuItem("Reset Scene"))
357 ResetScene();
358
359
360 if (ImGui::MenuItem("Exit"))
362
363 ImGui::EndMenu();
364 }
365
366 ImGui::EndMenuBar();
367 }
368
370
371 {
372 ImGui::Begin("Settings");
373 ImGui::Text("Renderer2D Stats:");
375 ImGui::Text("\tDraw Calls: %d", stats.DrawCalls);
376 ImGui::Text("\tQuad Count: %d", stats.QuadCount);
377 ImGui::Text("\tVertex Count: %d", stats.GetTotalVertexCount());
378 ImGui::Text("\tIndex Count: %d", stats.GetTotalIndexCount());
379 ImGui::Text("Application Settings:");
380 ImGui::Text("\tFPS: %.1f", ImGui::GetIO().Framerate);
381 if (ImGui::ColorEdit4("Background Color", glm::value_ptr(m_ClearColor)))
382 {
384 }
385 ImGui::End();
386 }
387
388 {
389 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 });
390 ImGui::Begin("Viewport");
391 m_ViewportFocused = ImGui::IsWindowFocused();
392 m_ViewportHovered = ImGui::IsWindowHovered();
394
395 ImVec2 viewportPanelSize = ImGui::GetContentRegionAvail();
396 if (m_ViewportSize != *((glm::vec2*)&viewportPanelSize) && viewportPanelSize.x > 0.0f && viewportPanelSize.y > 0)
397 {
400
402 }
403
404 ImVec2 viewportBoundsMin = ImGui::GetCursorScreenPos();
408
409 uint32_t textureID = m_Framebuffer->GetColorAttachmentRendererID();
410 ImGui::Image(textureID, ImVec2(m_ViewportSize.x, m_ViewportSize.y), ImVec2(0, 1), ImVec2(1, 0));
411
412 // Gizmos
414 if (selectedEntity && m_GizmoType != -1)
415 {
416 ImGuizmo::SetOrthographic(false);
417 ImGuizmo::SetDrawlist();
418 float windowWidth = (float)ImGui::GetWindowWidth();
419 float windowHeight = (float)ImGui::GetWindowHeight();
420 ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, windowWidth, windowHeight);
421
422 // Camera
423 // Runtime camera from entity
424 //auto cameraEntity = m_ActiveScene->GetPrimaryCameraEntity();
425 //const auto& camera = cameraEntity.GetComponent<CameraComponent>().Camera;
426 //const glm::mat4& cameraProjection = camera.GetProjection();
427 //glm::mat4 cameraView = glm::inverse(cameraEntity.GetComponent<TransformComponent>().GetTransform());
428
429 // Editor camera
430 const glm::mat4& cameraProjection = m_EditorCamera.GetProjection();
432
433 // Entity Transform
434 auto& tc = selectedEntity.GetComponent<TransformComponent>();
435 glm::mat4 transform = tc.GetTransform();
436
437 // Snapping
439 // use the editor layer snap values
441 if (m_GizmoType == ImGuizmo::OPERATION::ROTATE)
443 else if (m_GizmoType == ImGuizmo::OPERATION::SCALE)
445
446 float snapValues[3] = { snapValue, snapValue, snapValue };
447
448 ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(cameraProjection),
449 (ImGuizmo::OPERATION)m_GizmoType, ImGuizmo::LOCAL, glm::value_ptr(transform),
450 nullptr, snap ? snapValues : nullptr);
451
452 if (ImGuizmo::IsUsing())
453 {
454 glm::vec3 translation, rotation, scale;
456 tc.Translation = translation;
457 tc.Rotation = rotation;
458 tc.Scale = scale;
459 }
460 }
461
462 ImGui::End();
463 ImGui::PopStyleVar();
464 }
465 ImGui::End();
466 }
void Close()
Closes the application.
Definition Application.cpp:103
ImGuiLayer * GetImGuiLayer()
Retrieves the ImGui layer.
Definition Application.h:104
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:107
const glm::mat4 & GetProjection() const
Definition Camera.h:23
const glm::mat4 & GetViewMatrix() const
Definition EditorCamera.h:32
glm::vec2 m_ViewportBounds[2]
Definition EditorLayer.h:45
void OpenScene()
Definition EditorLayer.cpp:539
int m_GizmoType
Definition EditorLayer.h:49
void NewScene()
Definition EditorLayer.cpp:532
void SaveSceneAs()
Definition EditorLayer.cpp:555
glm::vec4 m_ClearColor
Definition EditorLayer.h:96
void ResetScene()
Definition EditorLayer.cpp:566
float m_TranslationSnap
Definition EditorLayer.h:50
float m_ScaleSnap
Definition EditorLayer.h:50
bool m_ViewportFocused
Definition EditorLayer.h:43
float m_RotationSnap
Definition EditorLayer.h:50
bool m_ViewportHovered
Definition EditorLayer.h:43
virtual void SetBlockEvents(bool block)
Definition ImGuiLayer.h:29
static bool IsKeyPressed(int keycode)
Checks if the specified key is currently pressed.
Definition WindowsInput.cpp:9
void OnResize(float width, float height)
Definition OrthographicCameraController.cpp:56
static void SetClearColor(const glm::vec4 &color)
Sets the clear color for the renderer.
Definition RenderCommand.h:29
static Statistics GetStats()
Retrieves the current rendering statistics.
Definition Renderer2D.cpp:521
Entity GetSelectedEntity() const
Definition SceneHierarchyPanel.h:21
void OnImGuiRender()
Definition SceneHierarchyPanel.cpp:28
@ LeftControl
Definition KeyCodes.h:143
bool DecomposeTransform(const glm::mat4 &transform, glm::vec3 &translation, glm::vec3 &rotation, glm::vec3 &scale)
Decomposes a transformation matrix into its translation, rotation, and scale components.
Definition Math.cpp:10

References Muto::Application::Close(), Muto::Application::Get(), Muto::Application::GetImGuiLayer(), Muto::Renderer2D::GetStats(), Muto::Input::IsKeyPressed(), Muto::Key::LeftControl, m_GizmoType, m_RotationSnap, m_ScaleSnap, m_TranslationSnap, m_ViewportFocused, m_ViewportHovered, NewScene(), OpenScene(), ResetScene(), SaveSceneAs(), and Muto::ImGuiLayer::SetBlockEvents().

◆ OnKeyPressed()

bool Muto::EditorLayer::OnKeyPressed ( KeyPressedEvent &  e)
private
481 {
482 // Shortcuts
483 if (e.GetRepeatCount() > 0)
484 return false;
485
488 switch (e.GetKeyCode())
489 {
490 // Scene Shortcuts
491 case Key::N:
492
493 if (control)
494 {
495 NewScene();
496 }
497 break;
498
499 case Key::O:
500 if (control)
501 {
502 OpenScene();
503 }
504 break;
505
506 case Key::S:
507 if (control && shift)
508 {
509 SaveSceneAs();
510 }
511 break;
512
513
514 // Gizmo Shortcuts
515 case Key::Q:
516 m_GizmoType = -1;
517 break;
518 case Key::W:
519 m_GizmoType = ImGuizmo::OPERATION::TRANSLATE;
520 break;
521 case Key::E:
522 m_GizmoType = ImGuizmo::OPERATION::ROTATE;
523 break;
524 case Key::R:
525 m_GizmoType = ImGuizmo::OPERATION::SCALE;
526 break;
527 }
528 return false;
529
530 }
@ RightControl
Definition KeyCodes.h:147
@ E
Definition KeyCodes.h:45
@ S
Definition KeyCodes.h:59
@ R
Definition KeyCodes.h:58
@ W
Definition KeyCodes.h:63
@ N
Definition KeyCodes.h:54
@ Q
Definition KeyCodes.h:57
@ O
Definition KeyCodes.h:55
@ LeftShift
Definition KeyCodes.h:142
@ RightShift
Definition KeyCodes.h:146

References Muto::KeyEvent::GetKeyCode(), Muto::KeyPressedEvent::GetRepeatCount(), Muto::Input::IsKeyPressed(), Muto::Key::LeftControl, Muto::Key::LeftShift, m_GizmoType, Muto::Key::N, NewScene(), Muto::Key::O, OpenScene(), Muto::Key::Q, Muto::Key::RightControl, Muto::Key::RightShift, Muto::Key::S, and SaveSceneAs().

Referenced by OnEvent().

◆ OnUpdate()

void Muto::EditorLayer::OnUpdate ( Timestep  ts)
overridevirtual

Called every frame to update the layer with the given timestep.

Parameters
tsThe timestep representing the time elapsed since the last update.

Reimplemented from Muto::Layer.

236 {
238
239 // Resize
240 if (Muto::FramebufferSpecification spec = m_Framebuffer->GetSpecification();
241 m_ViewportSize.x > 0.0f && m_ViewportSize.y > 0.0f &&
242 (spec.Width != (uint32_t)m_ViewportSize.x || spec.Height != (uint32_t)m_ViewportSize.y))
243 {
248 }
249
250 // Update
252 {
254 }
256
257
258 // Render
260 {
261 MU_PROFILE_SCOPE("Renderer Prep");
262 m_Framebuffer->Bind();
265 }
266
267
268 // Draw
269 {
270 {
271 MU_PROFILE_SCOPE("Entity Scene Update");
272 // Update scene
273 m_ActiveScene->OnUpdateRuntime(ts);
274 m_ActiveScene->OnUpdateEditor(ts, m_EditorCamera);
275 }
276 }
277
278 m_Framebuffer->Unbind();
279 }
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
void OnUpdate(Timestep ts)
Definition EditorCamera.cpp:46
void SetViewportSize(float width, float height)
Definition EditorCamera.h:30
void OnUpdate(Timestep ts)
Definition OrthographicCameraController.cpp:21
static void Clear()
Clears the rendering buffers.
Definition RenderCommand.h:35
static void ResetStats()
Resets the rendering statistics.
Definition Renderer2D.cpp:516
Specification for creating a Framebuffer.
Definition Framebuffer.h:14

References Muto::RenderCommand::Clear(), m_ViewportFocused, and Muto::Renderer2D::ResetStats().

◆ OpenScene()

void Muto::EditorLayer::OpenScene ( )
private
540 {
541 std::string filePath = FileDialogs::OpenFile("Vesper Scene (*.vesper)\0*.vesper\0");
542
543 if (!filePath.empty())
544 {
548
549 SceneSerializer serializer(m_ActiveScene);
550 serializer.Deserialize(filePath);
551 MU_CORE_INFO("Scene deserialized from: " + filePath);
552 }
553 }
static std::string OpenFile(const char *filter)
Opens a file dialog to select a file to open.
Definition LinuxPlatformUtils.cpp:160

References Muto::SceneSerializer::Deserialize(), and Muto::FileDialogs::OpenFile().

Referenced by OnImGuiRender(), and OnKeyPressed().

◆ ResetScene()

void Muto::EditorLayer::ResetScene ( )
private
567 {
568 MU_CORE_ASSERT(false, "Not implemented yet!");
569 }
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32

Referenced by OnImGuiRender().

◆ SaveSceneAs()

void Muto::EditorLayer::SaveSceneAs ( )
private
556 {
557 std::string filePath = FileDialogs::SaveFile("Vesper Scene (*.vesper)\0*.vesper\0");
558 if (!filePath.empty())
559 {
560 SceneSerializer serializer(m_ActiveScene);
561 serializer.Serialize(filePath);
562 MU_CORE_INFO("Scene serialized to: " + filePath);
563 }
564 }
static std::string SaveFile(const char *filter)
Opens a file dialog to select a location to save a file.
Definition LinuxPlatformUtils.cpp:165

References Muto::FileDialogs::SaveFile(), and Muto::SceneSerializer::Serialize().

Referenced by OnImGuiRender(), and OnKeyPressed().

Member Data Documentation

◆ lastFrameTime

float Muto::EditorLayer::lastFrameTime = 0.0f
private

◆ m_ActiveScene

Ref<Scene> Muto::EditorLayer::m_ActiveScene
private

◆ m_BackgroundColor

glm::vec4 Muto::EditorLayer::m_BackgroundColor = { 0.1f, 0.1f, 0.1f, 1.0f }
private
95{ 0.1f, 0.1f, 0.1f, 1.0f };

◆ m_CameraController

OrthographicCameraController Muto::EditorLayer::m_CameraController
private

◆ m_CameraEntity

Entity Muto::EditorLayer::m_CameraEntity
private

◆ m_CheckerboardTexture

Ref<Texture2D> Muto::EditorLayer::m_CheckerboardTexture
private

◆ m_ClearColor

glm::vec4 Muto::EditorLayer::m_ClearColor = { 0.1f, 0.3f, 0.3f, 1.0f }
private
96{ 0.1f, 0.3f, 0.3f, 1.0f };

◆ m_EditorCamera

EditorCamera Muto::EditorLayer::m_EditorCamera
private

◆ m_EditorScene

Ref<Scene> Muto::EditorLayer::m_EditorScene
private

◆ m_FireEntity

Entity Muto::EditorLayer::m_FireEntity
private

◆ m_FlatColorShader

Ref<Shader> Muto::EditorLayer::m_FlatColorShader
private

◆ m_Framebuffer

Ref<Framebuffer> Muto::EditorLayer::m_Framebuffer
private

◆ m_GizmoType

int Muto::EditorLayer::m_GizmoType = -1
private

Referenced by OnImGuiRender(), and OnKeyPressed().

◆ m_ParticleEmitCount

int Muto::EditorLayer::m_ParticleEmitCount = 100
private

◆ m_ParticleProps

ParticleProps Muto::EditorLayer::m_ParticleProps
private

◆ m_ParticleSystem

ParticleSystem Muto::EditorLayer::m_ParticleSystem
private

◆ m_PrimaryCamera

bool Muto::EditorLayer::m_PrimaryCamera = true
private

◆ m_RotationSnap

float Muto::EditorLayer::m_RotationSnap = 45.0f
private

Referenced by OnImGuiRender().

◆ m_ScaleSnap

float Muto::EditorLayer::m_ScaleSnap = 0.5f
private

Referenced by OnImGuiRender().

◆ m_SceneHierarchyPanel

SceneHierarchyPanel Muto::EditorLayer::m_SceneHierarchyPanel
private

◆ m_SceneState

SceneState Muto::EditorLayer::m_SceneState = SceneState::Edit
private

Referenced by OnEvent().

◆ m_SmokeEntity

Entity Muto::EditorLayer::m_SmokeEntity
private

◆ m_SpecialQuadColor

glm::vec4 Muto::EditorLayer::m_SpecialQuadColor = { 0.9f, 0.2f, 0.8f, 1.0f }
private
97{ 0.9f, 0.2f, 0.8f, 1.0f };

◆ m_specialQuadRotation

float Muto::EditorLayer::m_specialQuadRotation = 0.5f
private

◆ m_SpriteSheetCrystals

Ref<Texture2D> Muto::EditorLayer::m_SpriteSheetCrystals
private

◆ m_SpriteSheetCursedLands

Ref<Texture2D> Muto::EditorLayer::m_SpriteSheetCursedLands
private

◆ m_SpriteSheetFire

Ref<Texture2D> Muto::EditorLayer::m_SpriteSheetFire
private

◆ m_SpriteSheetRocks

Ref<Texture2D> Muto::EditorLayer::m_SpriteSheetRocks
private

◆ m_SpriteSheetSmoke

Ref<Texture2D> Muto::EditorLayer::m_SpriteSheetSmoke
private

◆ m_SpriteSheetTown

Ref<Texture2D> Muto::EditorLayer::m_SpriteSheetTown
private

◆ m_SquareColor

glm::vec4 Muto::EditorLayer::m_SquareColor = { 0.2f, 0.3f, 0.8f, 1.0f }
private
92{ 0.2f, 0.3f, 0.8f, 1.0f };

◆ m_squareRotation

float Muto::EditorLayer::m_squareRotation = 25.0f
private

◆ m_SquareVA

Ref<VertexArray> Muto::EditorLayer::m_SquareVA
private

◆ m_SubTextureFire

Ref<SubTexture2D> Muto::EditorLayer::m_SubTextureFire
private

◆ m_SubTextureSmoke

Ref<SubTexture2D> Muto::EditorLayer::m_SubTextureSmoke
private

◆ m_SubTextureTown

Ref<SubTexture2D> Muto::EditorLayer::m_SubTextureTown
private

◆ m_textureScale

float Muto::EditorLayer::m_textureScale = 1.0f
private

◆ m_TextureTintColor1

glm::vec4 Muto::EditorLayer::m_TextureTintColor1 = { 1.0f, 1.0f, 1.0f, 1.0f }
private
93{ 1.0f, 1.0f, 1.0f, 1.0f };

◆ m_TextureTintColor2

glm::vec4 Muto::EditorLayer::m_TextureTintColor2 = { 1.0f, 1.0f, 1.0f, 1.0f }
private
94{ 1.0f, 1.0f, 1.0f, 1.0f };

◆ m_TranslationSnap

float Muto::EditorLayer::m_TranslationSnap = 0.5f
private

Referenced by OnImGuiRender().

◆ m_UseSpecialQuadColor

bool Muto::EditorLayer::m_UseSpecialQuadColor = false
private

◆ m_ViewportBounds

glm::vec2 Muto::EditorLayer::m_ViewportBounds[2] = { {0,0}, {0,0} }
private
45{ {0,0}, {0,0} };

◆ m_ViewportFocused

bool Muto::EditorLayer::m_ViewportFocused = false
private

Referenced by OnImGuiRender(), and OnUpdate().

◆ m_ViewportHovered

bool Muto::EditorLayer::m_ViewportHovered = false
private

Referenced by OnImGuiRender().

◆ m_ViewportSize

glm::vec2 Muto::EditorLayer::m_ViewportSize = {0,0}
private
44{0,0};

◆ s_TextureMap

std::unordered_map<char, Ref<SubTexture2D> > Muto::EditorLayer::s_TextureMap
private

◆ scene1

bool Muto::EditorLayer::scene1 = false
private

◆ scene2

bool Muto::EditorLayer::scene2 = false
private

◆ scene3

bool Muto::EditorLayer::scene3 = false
private

◆ scene4

bool Muto::EditorLayer::scene4 = false
private

◆ useEntityScene

bool Muto::EditorLayer::useEntityScene = true
private

The documentation for this class was generated from the following files: