12#include "EditorProperties.hpp"
13#include "ProjectProperties.hpp"
18#include "components/DebugConsole.hpp"
21#include <nlohmann/json.hpp>
43 Editor(
const char* title,
int width,
int height,
GameInfo gInfo,
const std::string& projectBinaryPath);
51 void update(
float deltaTime)
override;
56 void processEvent(
const SDL_Event& event,
float deltaTime)
override;
140 void drawGizmo(
const glm::vec2& viewportPos,
const glm::vec2& viewportSize);
153 float raySphereIntersect(
const glm::vec3& rayOrigin,
const glm::vec3& rayDir,
const glm::vec3& sphereCenter,
float sphereRadius);
164 float rayTriangleIntersect(
const glm::vec3& rayOrigin,
const glm::vec3& rayDir,
const glm::vec3& v0,
const glm::vec3& v1,
const glm::vec3& v2);
179 std::ofstream file(filename);
180 if (file.is_open()) {
181 nlohmann::json j = data;
192 std::ifstream file(filename);
193 if (file.is_open()) {
198 }
catch (
const std::exception& e) {
211 std::ofstream file(filename);
212 if (file.is_open()) {
213 nlohmann::json j = data;
224 std::ifstream file(filename);
225 if (file.is_open()) {
230 }
catch (
const std::exception& e) {
237 std::deque<std::unique_ptr<ICommand>> m_undoStack;
238 std::deque<std::unique_ptr<ICommand>> m_redoStack;
239 const size_t MAX_UNDO_STEPS = 50;
243 m_undoStack.push_back(std::unique_ptr<ICommand>(cmd));
244 if (m_undoStack.size() > MAX_UNDO_STEPS) m_undoStack.pop_front();
251 std::unordered_map<std::string, nlohmann::json> components;
252 bool hasData =
false;
255 bool m_gizmoWasUsing =
false;
256 glm::vec3 m_gizmoStartPos;
257 glm::vec3 m_gizmoStartRot;
258 glm::vec3 m_gizmoStartScale;
260 bool m_isAssetBrowserFocused =
false;
262 glm::uvec2 m_viewportSize = {1280, 720};
263 std::unique_ptr<EditorCameraObject> m_camera;
264 std::unique_ptr<EditorMenuBar> m_editorMenuBar;
265 std::pair<bool, GameObject*> m_selectedObject = {
false,
nullptr};
266 std::unique_ptr<AssetBrowser> m_assetBrowser;
267 BrowserIcons m_icons;
269 std::string m_pendingSceneToLoad =
"";
270 bool m_waitForGui =
true;
272 std::string m_projectBinaryPath;
274 ImGuizmo::OPERATION m_currentGizmoOperation = ImGuizmo::TRANSLATE;
275 ImGuizmo::MODE m_currentGizmoMode = ImGuizmo::WORLD;
276 bool m_useSnap =
false;
277 float m_snapValue[3] = { 0.5f, 0.5f, 0.5f };
279 bool m_isHoveringGizmoUI =
false;
281 EditorProperties m_editorProperties;
282 EditorProperties m_SavedEditorProperties;
284 ProjectProperties m_projectProperties;
285 ProjectProperties m_SavedProjectProperties;
289 bool m_refresh =
false;
290 bool showConsole =
false;
Class responsible for displaying and navigating project assets within an ImGUI window.
A specialized camera object for use within the editor, supporting free-fly movement and input process...
Command pattern implementation for Editor Undo/Redo system.
Contains main Engine class.
Class responsible for displaying and navigating project assets within an ImGUI window.
void processEvent(const SDL_Event &event, float deltaTime) override
Overrides the Engine's processEvent function to handle editor-specific events (e.g....
void LoadConfig(EditorProperties &data, const std::string &filename)
Loads the EditorProperties configuration from a JSON file.
void LoadProjectConfig(ProjectProperties &data, const std::string &filename)
Loads the ProjectProperties configuration from a JSON file.
bool IsEditor() override
Returns true if the engine is running in editor mode.
void Undo()
Undoes the last action performed in the editor.
void PushCommand(ICommand *cmd)
Pushes a command onto the undo stack and clears the redo stack.
void DeleteSelectedObject()
Deletes the selected object from the scene.
float raySphereIntersect(const glm::vec3 &rayOrigin, const glm::vec3 &rayDir, const glm::vec3 &sphereCenter, float sphereRadius)
Performs a ray-sphere intersection test.
void refreshForObject() override
Overrides the base Engine function to trigger a frame and refresh.
void SaveProjectConfig(const ProjectProperties &data, const std::string &filename)
Saves the current ProjectProperties configuration to a JSON file.
void drawEditorLayout(const SceneRenderData &data, glm::uvec2 &outNewResolution)
Helper to draw the ImGUI dockspace and viewport window for the editor.
void drawGizmo(const glm::vec2 &viewportPos, const glm::vec2 &viewportSize)
Draws the ImGuizmo for the currently selected object.
ProjectProperties * getProjectProperties()
Gets a pointer to the mutable project properties.
EditorProperties * getEditorProperties()
Gets a pointer to the mutable editor properties.
void CopySelectedObject()
Copies the selected object to the clipboard.
AssetBrowser * getAssetBrowser() const
Gets a pointer to the AssetBrowser instance.
void Redo()
Redoes the last undone action in the editor.
void OnHotReload()
Handler for post-hot-reload operations.
void render() override
Overrides the Engine's render function to inject the Editor UI logic (dockspace, viewport,...
void SaveConfig(const EditorProperties &data, const std::string &filename)
Saves the current EditorProperties configuration to a JSON file.
void HandleMeshDrop(const std::string &filepath, vex::Entity parent=vex::NULL_ENTITY)
Handles the dropping of a mesh asset.
void ExtractObjectByEntity(vex::Entity entity, std::pair< bool, vex::GameObject * > &selectedObject)
Retrieves the GameObject corresponding to a given entity ID and updates the selected object pair.
void setFullscreen(bool enabled, bool exclusive=false) override
Overrides the Engine's setFullscreen function to disable auto fullscreen by gameModule.
std::string getProjectBinaryPath() const
Gets the path to the project's binary directory.
void DuplicateSelectedObject()
Duplicates the selected object in the scene.
Editor(const char *title, int width, int height, GameInfo gInfo, const std::string &projectBinaryPath)
Constructs the Editor.
const BrowserIcons & GetEditorIcons() const
Gets the collection of icons used within the editor's UI.
void ShowConsole()
Shows the debug console.
void ProcessEditorShortcuts()
Processes editor shortcuts.
float rayTriangleIntersect(const glm::vec3 &rayOrigin, const glm::vec3 &rayDir, const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2)
Performs a ray-triangle intersection test (using the Möller–Trumbore algorithm).
void PasteObjectToScene()
Pastes the object from the clipboard to the scene.
void requestSceneReload(const std::string &scenePath)
Requests a scene reload with a specific path. The reload is typically executed in the main update loo...
void loadAssetIcons()
Loads the texture icons used for the Asset Browser and other UI elements.
void update(float deltaTime) override
Overrides the Engine's update function to handle editor-specific logic.
Engine(const char *title, int width, int height, GameInfo gInfo)
Constructor for the Engine class.
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
void VEX_EXPORT handle_exception(const std::exception &e)
Handles an exception based on build configuration.
constexpr Entity NULL_ENTITY
Special entity value indicating an invalid or null entity.
Structure to hold all configurable editor settings and properties.
Structure to hold all configurable project settings and properties.
Structure holding texture IDs for various asset types displayed in the browser.
this struct contains information about the game. like project name and version.
Data structure to pass state between render stages.