166 lines
4.3 KiB
C++
166 lines
4.3 KiB
C++
//
|
|
// Created by sfd on 25-11-29.
|
|
//
|
|
|
|
#ifndef EDITORLAYER_H
|
|
#define EDITORLAYER_H
|
|
|
|
#include "Prism.h"
|
|
#include "Prism/Editor/AssetsManagerPanel.h"
|
|
#include "Prism/Editor/ObjectsPanel.h"
|
|
#include "Prism/Editor/SceneHierachyPanel.h"
|
|
|
|
namespace Prism
|
|
{
|
|
class EditorLayer : public Layer
|
|
{
|
|
public:
|
|
EditorLayer();
|
|
virtual ~EditorLayer();
|
|
|
|
virtual void OnAttach() override;
|
|
virtual void OnDetach() override;
|
|
virtual void OnUpdate(TimeStep deltaTime) override;
|
|
virtual void OnImGuiRender() override;
|
|
virtual void OnEvent(Event& e) override;
|
|
|
|
private:
|
|
bool OnKeyPressedEvent(KeyPressedEvent& e);
|
|
bool OnMouseButtonPressedEvent(MouseButtonPressedEvent& e);
|
|
|
|
void ShowBoundingBoxes(bool show, bool onTop = false);
|
|
void SelectEntity(Entity entity);
|
|
|
|
void UpdateWindowTitle(const std::string& sceneName);
|
|
private:
|
|
std::pair<float, float> GetMouseViewportSpace() const;
|
|
std::pair<glm::vec3, glm::vec3> CastRay(float mx, float my);
|
|
|
|
struct SelectedSubmesh
|
|
{
|
|
Prism::Entity Entity;
|
|
Submesh* Mesh = nullptr;
|
|
float Distance = 0.0f;
|
|
};
|
|
void OnSelected(const SelectedSubmesh& selectionContext);
|
|
void OnEntityDeleted(Entity e);
|
|
Ray CastMouseRay();
|
|
|
|
void NewScene();
|
|
void OpenScene();
|
|
void OpenScene(const std::string& filepath);
|
|
void SaveScene();
|
|
void SaveSceneAs();
|
|
|
|
void OnScenePlay();
|
|
void OnSceneStop();
|
|
|
|
float GetSnapValue() const;
|
|
private:
|
|
Scope<SceneHierarchyPanel> m_SceneHierarchyPanel;
|
|
Scope<AssetsManagerPanel> m_AssetManagerPanel;
|
|
Scope<ObjectsPanel> m_ObjectsPanel;
|
|
|
|
Ref<Scene> m_ActiveScene;
|
|
Ref<Scene> m_RuntimeScene, m_EditorScene;
|
|
std::string m_SceneFilePath;
|
|
|
|
bool m_ReloadScriptOnPlay = false;
|
|
|
|
EditorCamera m_EditorCamera;
|
|
|
|
Ref<Material> m_SphereBaseMaterial;
|
|
Ref<Material> m_MeshMaterial;
|
|
|
|
std::vector<Ref<MaterialInstance>> m_MetalSphereMaterialInstances;
|
|
std::vector<Ref<MaterialInstance>> m_DielectricSphereMaterialInstances;
|
|
|
|
|
|
// Imguizmo
|
|
glm::vec2 m_ViewportBounds[2] = {};
|
|
int m_GizmoType = -1; // -1 = no gizmo
|
|
float m_SnapValue = 0.5f;
|
|
float m_RotationSnapValue = 45.0f;
|
|
|
|
enum class SelectionMode
|
|
{
|
|
None = 0, Entity = 1, SubMesh = 2
|
|
};
|
|
SelectionMode m_SelectionMode = SelectionMode::Entity;
|
|
|
|
std::vector<SelectedSubmesh> m_SelectionContext;
|
|
glm::mat4* m_RelativeTransform = nullptr;
|
|
|
|
|
|
struct AlbedoInput
|
|
{
|
|
glm::vec3 Color = { 0.972f, 0.96f, 0.915f }; // Silver, from https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/PhysicallyBased
|
|
Ref<Texture2D> TextureMap;
|
|
bool SRGB = true;
|
|
bool UseTexture = false;
|
|
};
|
|
// AlbedoInput m_AlbedoInput;
|
|
|
|
struct NormalInput
|
|
{
|
|
Ref<Texture2D> TextureMap;
|
|
bool UseTexture = false;
|
|
};
|
|
// NormalInput m_NormalInput;
|
|
|
|
struct MetalnessInput
|
|
{
|
|
float Value = 1.0f;
|
|
Ref<Texture2D> TextureMap;
|
|
bool UseTexture = false;
|
|
};
|
|
// MetalnessInput m_MetalnessInput;
|
|
|
|
struct RoughnessInput
|
|
{
|
|
float Value = 1.0f;
|
|
Ref<Texture2D> TextureMap;
|
|
bool UseTexture = false;
|
|
};
|
|
// RoughnessInput m_RoughnessInput;
|
|
|
|
|
|
// PBR params
|
|
bool m_RadiancePrefilter = false;
|
|
|
|
float m_EnvMapRotation = 0.0f;
|
|
|
|
|
|
// Editor resources
|
|
Ref<Texture2D> m_CheckerboardTex;
|
|
Ref<Texture2D> m_PlayButtonTex;
|
|
|
|
|
|
// configure button
|
|
bool m_AllowViewportCameraEvents = false;
|
|
bool m_DrawOnTopBoundingBoxes = false;
|
|
|
|
bool m_UIShowBoundingBoxes = false;
|
|
bool m_UIShowBoundingBoxesOnTop = false;
|
|
|
|
enum class SceneType : uint32_t
|
|
{
|
|
Spheres = 0, Model = 1
|
|
};
|
|
SceneType m_SceneType;
|
|
|
|
bool m_ViewportPanelHovered = false;
|
|
bool m_ViewportPanelFocused = false;
|
|
bool m_ShowPhysicsSettings = false;
|
|
|
|
enum class SceneState
|
|
{
|
|
Edit = 0, Play = 1, Pause = 2
|
|
};
|
|
SceneState m_SceneState = SceneState::Edit;
|
|
};
|
|
}
|
|
|
|
|
|
#endif //EDITORLAYER_H
|