From 76880e25b66a11075d53dcc7fe64a60920d02098 Mon Sep 17 00:00:00 2001 From: Arnau Alier Torres Date: Wed, 23 Apr 2025 00:31:06 +0200 Subject: [PATCH] working on mesh explorer to load meshes --- Deer/Include/Deer/Asset.h | 2 + Deer/Include/Deer/ComponentScript.h | 2 + Deer/Include/Deer/Components.h | 2 + Deer/Include/Deer/DataStore.h | 3 +- Deer/Include/Deer/EntryPoint.h | 3 + Deer/Include/Deer/Log.h | 2 + Deer/Include/Deer/Memory.h | 2 + Deer/Include/Deer/Path.h | 2 + Deer/Include/Deer/Scene.h | 21 ++++-- DeerStudio/src/DeerStudio/DeerStudio.cpp | 8 ++- .../Editor/MeshExplorer/MeshExplorer.cpp | 70 +++++++++++++++++++ .../Editor/MeshExplorer/MeshExplorer.h | 7 ++ .../DeerStudio/Editor/PropertiesPannel.cpp | 2 +- .../src/DeerStudio/Editor/PropertiesPannel.h | 2 +- .../Editor/Terrain/TerrainEditor.cpp | 2 +- .../DeerStudio/Editor/Terrain/TerrainEditor.h | 12 ++-- .../src/DeerStudio/Editor/TreePannel.cpp | 2 +- DeerStudio/src/DeerStudio/Editor/TreePannel.h | 2 +- roe/imgui.ini | 44 +++++++----- 19 files changed, 150 insertions(+), 40 deletions(-) create mode 100644 DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp create mode 100644 DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h diff --git a/Deer/Include/Deer/Asset.h b/Deer/Include/Deer/Asset.h index e498a95..cc61a87 100755 --- a/Deer/Include/Deer/Asset.h +++ b/Deer/Include/Deer/Asset.h @@ -6,6 +6,8 @@ #include "Deer/Log.h" #include "Deer/Path.h" +// File to manage Assets + namespace Deer { template class Asset { diff --git a/Deer/Include/Deer/ComponentScript.h b/Deer/Include/Deer/ComponentScript.h index 0757cdc..b4bc771 100755 --- a/Deer/Include/Deer/ComponentScript.h +++ b/Deer/Include/Deer/ComponentScript.h @@ -7,6 +7,8 @@ class asIScriptObject; class asIScriptFunction; class asIScriptContext; +// Components but for scripts + namespace Deer { struct ScriptAttribute; using ScriptAttributeMap = std::unordered_map; diff --git a/Deer/Include/Deer/Components.h b/Deer/Include/Deer/Components.h index ba13e90..08ec791 100755 --- a/Deer/Include/Deer/Components.h +++ b/Deer/Include/Deer/Components.h @@ -14,6 +14,8 @@ #define ENTITY_MAX_CHILDREN 64 +// Here we define the core components of the ECS + namespace Deer { class ComponentScriptInstance; diff --git a/Deer/Include/Deer/DataStore.h b/Deer/Include/Deer/DataStore.h index f7caf5c..3847df1 100755 --- a/Deer/Include/Deer/DataStore.h +++ b/Deer/Include/Deer/DataStore.h @@ -13,12 +13,13 @@ #define DEER_VOXEL_ASPECT_PATH "voxels/aspect" #define DEER_VOXEL_TEXTURE_PATH "voxels/textures" #define DEER_VOXEL_SHADER_PATH "voxels/shaders" -#define DEER_OBJECT_PATH "objects" +#define DEER_MESH_PATH "meshes" #define DEER_BIN_PATH "bin" #define DEER_TEMP_PATH "tmp" namespace Deer { + // Namespace to manage memory interactions namespace DataStore { void createFolder(const Path& path); diff --git a/Deer/Include/Deer/EntryPoint.h b/Deer/Include/Deer/EntryPoint.h index cfcdbb4..a4d89a8 100755 --- a/Deer/Include/Deer/EntryPoint.h +++ b/Deer/Include/Deer/EntryPoint.h @@ -2,6 +2,9 @@ #include "Deer/Application.h" #include "Deer/Log.h" +// File to define the entry point, only use once +// This makes easier to manage + extern Deer::Application* createApplication(int argc, char** argv); namespace Deer { diff --git a/Deer/Include/Deer/Log.h b/Deer/Include/Deer/Log.h index 4d3ea34..059610f 100755 --- a/Deer/Include/Deer/Log.h +++ b/Deer/Include/Deer/Log.h @@ -7,6 +7,8 @@ namespace spdlog { class logger; } +// Simple file to define logs functions optimized depending on the compilation + namespace Deer { class Log { public: diff --git a/Deer/Include/Deer/Memory.h b/Deer/Include/Deer/Memory.h index 507e6ed..07028a9 100644 --- a/Deer/Include/Deer/Memory.h +++ b/Deer/Include/Deer/Memory.h @@ -1,6 +1,8 @@ #pragma once #include +// Simple file to redefine memory for easier usage + namespace Deer { template using Scope = std::unique_ptr; diff --git a/Deer/Include/Deer/Path.h b/Deer/Include/Deer/Path.h index 10b88d2..d9bdbff 100755 --- a/Deer/Include/Deer/Path.h +++ b/Deer/Include/Deer/Path.h @@ -1,6 +1,8 @@ #pragma once #include +// Simple file to rename path for easier usage + namespace Deer { using Path = std::filesystem::path; diff --git a/Deer/Include/Deer/Scene.h b/Deer/Include/Deer/Scene.h index 8ce7cb0..fd93ce6 100755 --- a/Deer/Include/Deer/Scene.h +++ b/Deer/Include/Deer/Scene.h @@ -15,6 +15,8 @@ namespace Deer { class VoxelWorldProps; class Environment; + // A scene is a 3d simulation with its environment and voxel world in case + // of initialized, here things can be simulated class Scene { public: Scene(); @@ -24,36 +26,41 @@ namespace Deer { void createVoxelWorld(const VoxelWorldProps&); void deleteVoxelWorld(); + + // Resets all scene to 0 but conserving the memory making it much faster + // than creating another instance void clear(); + // This is the cycle to execution void beginExecution(); void updateInternalVars(); void endExecution(); - public: inline Environment& getMainEnviroment() { return *m_enviroment; } inline VoxelWorld& getVoxelWorld() { return *m_voxelWorld; } inline bool isVoxelWorldInitialized() { return m_voxelWorld != nullptr; } inline bool getExecutingState() { return m_isExecuting; } - - private: - Scope m_enviroment; - Scope m_voxelWorld; - - bool m_isExecuting = false; #ifdef DEER_RENDER public: + // This function renders with the default camera in the environment void render(); void render(SceneCamera); + inline GizmoRenderer& getMainGizmoRenderer() { return m_gizmoRenderer; } private: GizmoRenderer m_gizmoRenderer; #endif + private: + Scope m_enviroment; + Scope m_voxelWorld; + + bool m_isExecuting = false; }; + // Namespace to manage scenes in memory namespace SceneDataStore { void loadScene(Scene& scene, const Path& name); void exportScene(const Scene& scene, const Path& name); diff --git a/DeerStudio/src/DeerStudio/DeerStudio.cpp b/DeerStudio/src/DeerStudio/DeerStudio.cpp index 8daf2b7..9802e83 100755 --- a/DeerStudio/src/DeerStudio/DeerStudio.cpp +++ b/DeerStudio/src/DeerStudio/DeerStudio.cpp @@ -10,6 +10,7 @@ #include "DeerStudio/Editor/Fonts.h" #include "DeerStudio/Editor/GamePannel.h" #include "DeerStudio/Editor/Icons.h" +#include "DeerStudio/Editor/MeshExplorer/MeshExplorer.h" #include "DeerStudio/Editor/PropertiesPannel.h" #include "DeerStudio/Editor/SceneExplorer.h" #include "DeerStudio/Editor/Terrain/TerrainEditor.h" @@ -132,9 +133,10 @@ namespace Deer { // ---- PANNELS ----- // sceneExplorer_onImGUI(); - TreePannel::treePannel_onImGui(); - PropertiesPannel::propertiesPannel_onImgui(); - TerrainEditor::terrainEditor_onImGui(); + TreePannel::onImgui(); + PropertiesPannel::onImgui(); + MeshExplorer::onImGui(); + TerrainEditor::onImGui(); viewport_onImGui(); // ---- PANNELS ----- diff --git a/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp b/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp new file mode 100644 index 0000000..0fda7dc --- /dev/null +++ b/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp @@ -0,0 +1,70 @@ +#include "MeshExplorer.h" + +#include "Deer/DataStore.h" +#include "Deer/Path.h" +#include "DeerStudio/Editor/EditorUtils.h" +#include "DeerStudio/Editor/Icons.h" +#include "imgui.h" + +namespace Deer { + namespace MeshExplorer { + Path m_meshExplorerPath(DEER_MESH_PATH); + void drawFolder(const Path& path); + } // namespace MeshExplorer + + void MeshExplorer::onImGui() { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10)); + ImGui::Begin("Mesh Explorer", (bool*)0, ImGuiWindowFlags_MenuBar); + ImGui::PopStyleVar(); + + ImGui::Text("%s", m_meshExplorerPath.generic_string().c_str()); + DataStore::createFolder(DEER_MESH_PATH); + + setupColumns(ICON_MIN_SIZE + 80); + + if (m_meshExplorerPath != DEER_MESH_PATH) { + drawFolder(".."); + + float cursorOffset = + (ICON_MIN_SIZE - ImGui::CalcTextSize("..").x) / 2; + ImGui::SetCursorPos(ImVec2(cursorOffset + ImGui::GetCursorPos().x, + ImGui::GetCursorPos().y)); + ImGui::Text(".."); + + ImGui::NextColumn(); + } + + for (const auto& entry : + std::filesystem::directory_iterator(m_meshExplorerPath)) { + if (entry.is_directory()) + drawFolder(entry.path()); + else { + } + + float cursorOffset = + (ICON_MIN_SIZE - + ImGui::CalcTextSize(entry.path().stem().string().c_str()).x) / + 2; + ImGui::SetCursorPos(ImVec2(cursorOffset + ImGui::GetCursorPos().x, + ImGui::GetCursorPos().y)); + ImGui::Text("%s", entry.path().stem().string().c_str()); + + ImGui::NextColumn(); + } + ImGui::Columns(); + ImGui::End(); + } + + void MeshExplorer::drawFolder(const Path& path) { + ImGui::Image((void*)(uint64_t)Icons::folder_icon->getTextureID(), + ImVec2(ICON_MIN_SIZE, ICON_MIN_SIZE), ImVec2(0, 1), + ImVec2(1, 0)); + + if (ImGui::IsItemClicked(0) && ImGui::IsMouseDoubleClicked(0)) { + if (path == "..") + m_meshExplorerPath = m_meshExplorerPath.parent_path(); + else + m_meshExplorerPath = path; + } + } +} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h b/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h new file mode 100644 index 0000000..3a0d3bd --- /dev/null +++ b/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h @@ -0,0 +1,7 @@ +#pragma once + +namespace Deer { + namespace MeshExplorer { + void onImGui(); + } +} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.cpp b/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.cpp index ea38b35..1940ad3 100755 --- a/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.cpp +++ b/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.cpp @@ -38,7 +38,7 @@ namespace Deer { return state; } - void PropertiesPannel::propertiesPannel_onImgui() { + void PropertiesPannel::onImgui() { ImGui::Begin("Properties"); if (ActiveEntity::count() == 0) { diff --git a/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.h b/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.h index 4fbed18..087a7d4 100755 --- a/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.h +++ b/DeerStudio/src/DeerStudio/Editor/PropertiesPannel.h @@ -5,6 +5,6 @@ namespace Deer { namespace PropertiesPannel { - void propertiesPannel_onImgui(); + void onImgui(); } // namespace PropertiesPannel } // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp index 5b8bc59..e637de6 100755 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.cpp @@ -21,7 +21,7 @@ namespace Deer { TerrainEditMode terrainEditMode = TerrainEditMode_Add; } // namespace TerrainEditor - void TerrainEditor::terrainEditor_onImGui() { + void TerrainEditor::onImGui() { ImGui::Begin("Terrain Editor"); if (!Project::m_scene.isVoxelWorldInitialized()) { diff --git a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.h b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.h index bd5abe1..f58e101 100755 --- a/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.h +++ b/DeerStudio/src/DeerStudio/Editor/Terrain/TerrainEditor.h @@ -20,12 +20,12 @@ namespace Deer { extern VoxelCordinates voxelRayCoords; extern VoxelCordinates voxelFaceRayCoords; extern uint16_t selectedVoxelID; - extern uint8_t voxelSelectMode; + extern uint8_t voxelSelectMode; - extern VoxelCordinates selectedVoxelStart; - extern VoxelCordinates selectedVoxelEnd; + extern VoxelCordinates selectedVoxelStart; + extern VoxelCordinates selectedVoxelEnd; - void terrainEditor_onImGui(); + void onImGui(); void createVoxelWorldPopup(); void voxelSelector(); void voxelRay(); @@ -34,5 +34,5 @@ namespace Deer { void fill(); void info(); void empty(); - } -} \ No newline at end of file + } // namespace TerrainEditor +} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/TreePannel.cpp b/DeerStudio/src/DeerStudio/Editor/TreePannel.cpp index 129295b..8e271ca 100755 --- a/DeerStudio/src/DeerStudio/Editor/TreePannel.cpp +++ b/DeerStudio/src/DeerStudio/Editor/TreePannel.cpp @@ -20,7 +20,7 @@ namespace Deer { Entity* m_contextMenuEntity = nullptr; } // namespace TreePannel - void TreePannel::treePannel_onImGui() { + void TreePannel::onImgui() { ImGui::Begin("Tree Pannel", (bool*)0, ImGuiWindowFlags_MenuBar); m_isRightClickHandled = false; diff --git a/DeerStudio/src/DeerStudio/Editor/TreePannel.h b/DeerStudio/src/DeerStudio/Editor/TreePannel.h index 3e1e3d2..2cd0e05 100755 --- a/DeerStudio/src/DeerStudio/Editor/TreePannel.h +++ b/DeerStudio/src/DeerStudio/Editor/TreePannel.h @@ -2,6 +2,6 @@ namespace Deer { namespace TreePannel { - void treePannel_onImGui(); + void onImgui(); } } \ No newline at end of file diff --git a/roe/imgui.ini b/roe/imgui.ini index bd907d0..9107dd7 100644 --- a/roe/imgui.ini +++ b/roe/imgui.ini @@ -1,6 +1,6 @@ [Window][DockSpace Demo] Pos=0,0 -Size=1628,720 +Size=1280,720 Collapsed=0 [Window][Debug##Default] @@ -9,47 +9,55 @@ Size=400,400 Collapsed=0 [Window][Properties] -Pos=1236,24 -Size=392,696 +Pos=888,24 +Size=392,344 Collapsed=0 DockId=0x00000004,0 [Window][Game Window] Pos=368,24 -Size=866,696 +Size=518,344 Collapsed=0 DockId=0x00000006,1 [Window][Tree Pannel] Pos=0,24 -Size=366,696 +Size=366,344 Collapsed=0 DockId=0x00000005,0 [Window][Terrain Editor] -Pos=1236,24 -Size=392,696 +Pos=888,24 +Size=392,344 Collapsed=0 DockId=0x00000004,1 [Window][Viewport] Pos=368,24 -Size=866,696 +Size=518,344 Collapsed=0 DockId=0x00000006,0 [Window][Scene Explorer] -Pos=0,929 -Size=2560,442 +Pos=0,389 +Size=1280,331 Collapsed=0 DockId=0x00000002,0 -[Docking][Data] -DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1628,696 Split=Y - DockNode ID=0x00000001 Parent=0xA1672E74 SizeRef=2560,903 Split=X Selected=0x13926F0B - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1234,779 Split=X Selected=0x13926F0B - DockNode ID=0x00000005 Parent=0x00000003 SizeRef=366,779 Selected=0xBD1B42A3 - DockNode ID=0x00000006 Parent=0x00000003 SizeRef=866,779 CentralNode=1 Selected=0x13926F0B - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=392,779 Selected=0x199AB496 - DockNode ID=0x00000002 Parent=0xA1672E74 SizeRef=2560,442 Selected=0xCF339702 +[Window][Mesh Explorer] +Pos=0,370 +Size=1280,350 +Collapsed=0 +DockId=0x00000008,0 + +[Docking][Data] +DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y + DockNode ID=0x00000007 Parent=0xA1672E74 SizeRef=1280,344 Split=Y + DockNode ID=0x00000001 Parent=0x00000007 SizeRef=2560,363 Split=X Selected=0x13926F0B + DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1234,779 Split=X Selected=0x13926F0B + DockNode ID=0x00000005 Parent=0x00000003 SizeRef=366,779 Selected=0xBD1B42A3 + DockNode ID=0x00000006 Parent=0x00000003 SizeRef=866,779 CentralNode=1 Selected=0x13926F0B + DockNode ID=0x00000004 Parent=0x00000001 SizeRef=392,779 Selected=0x2A2C795E + DockNode ID=0x00000002 Parent=0x00000007 SizeRef=2560,331 Selected=0xCF339702 + DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,350 Selected=0x7F7E0F9C