working on mesh explorer to load meshes

This commit is contained in:
Arnau Alier Torres 2025-04-23 00:31:06 +02:00
parent 66737f4eec
commit 76880e25b6
19 changed files with 150 additions and 40 deletions

View File

@ -6,6 +6,8 @@
#include "Deer/Log.h" #include "Deer/Log.h"
#include "Deer/Path.h" #include "Deer/Path.h"
// File to manage Assets
namespace Deer { namespace Deer {
template <typename T> template <typename T>
class Asset { class Asset {

View File

@ -7,6 +7,8 @@ class asIScriptObject;
class asIScriptFunction; class asIScriptFunction;
class asIScriptContext; class asIScriptContext;
// Components but for scripts
namespace Deer { namespace Deer {
struct ScriptAttribute; struct ScriptAttribute;
using ScriptAttributeMap = std::unordered_map<std::string, ScriptAttribute>; using ScriptAttributeMap = std::unordered_map<std::string, ScriptAttribute>;

View File

@ -14,6 +14,8 @@
#define ENTITY_MAX_CHILDREN 64 #define ENTITY_MAX_CHILDREN 64
// Here we define the core components of the ECS
namespace Deer { namespace Deer {
class ComponentScriptInstance; class ComponentScriptInstance;

View File

@ -13,12 +13,13 @@
#define DEER_VOXEL_ASPECT_PATH "voxels/aspect" #define DEER_VOXEL_ASPECT_PATH "voxels/aspect"
#define DEER_VOXEL_TEXTURE_PATH "voxels/textures" #define DEER_VOXEL_TEXTURE_PATH "voxels/textures"
#define DEER_VOXEL_SHADER_PATH "voxels/shaders" #define DEER_VOXEL_SHADER_PATH "voxels/shaders"
#define DEER_OBJECT_PATH "objects" #define DEER_MESH_PATH "meshes"
#define DEER_BIN_PATH "bin" #define DEER_BIN_PATH "bin"
#define DEER_TEMP_PATH "tmp" #define DEER_TEMP_PATH "tmp"
namespace Deer { namespace Deer {
// Namespace to manage memory interactions
namespace DataStore { namespace DataStore {
void createFolder(const Path& path); void createFolder(const Path& path);

View File

@ -2,6 +2,9 @@
#include "Deer/Application.h" #include "Deer/Application.h"
#include "Deer/Log.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); extern Deer::Application* createApplication(int argc, char** argv);
namespace Deer { namespace Deer {

View File

@ -7,6 +7,8 @@ namespace spdlog {
class logger; class logger;
} }
// Simple file to define logs functions optimized depending on the compilation
namespace Deer { namespace Deer {
class Log { class Log {
public: public:

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <memory> #include <memory>
// Simple file to redefine memory for easier usage
namespace Deer { namespace Deer {
template <typename T> template <typename T>
using Scope = std::unique_ptr<T>; using Scope = std::unique_ptr<T>;

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <filesystem> #include <filesystem>
// Simple file to rename path for easier usage
namespace Deer { namespace Deer {
using Path = std::filesystem::path; using Path = std::filesystem::path;

View File

@ -15,6 +15,8 @@ namespace Deer {
class VoxelWorldProps; class VoxelWorldProps;
class Environment; 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 { class Scene {
public: public:
Scene(); Scene();
@ -24,36 +26,41 @@ namespace Deer {
void createVoxelWorld(const VoxelWorldProps&); void createVoxelWorld(const VoxelWorldProps&);
void deleteVoxelWorld(); void deleteVoxelWorld();
// Resets all scene to 0 but conserving the memory making it much faster
// than creating another instance
void clear(); void clear();
// This is the cycle to execution
void beginExecution(); void beginExecution();
void updateInternalVars(); void updateInternalVars();
void endExecution(); void endExecution();
public:
inline Environment& getMainEnviroment() { return *m_enviroment; } inline Environment& getMainEnviroment() { return *m_enviroment; }
inline VoxelWorld& getVoxelWorld() { return *m_voxelWorld; } inline VoxelWorld& getVoxelWorld() { return *m_voxelWorld; }
inline bool isVoxelWorldInitialized() { inline bool isVoxelWorldInitialized() {
return m_voxelWorld != nullptr; return m_voxelWorld != nullptr;
} }
inline bool getExecutingState() { return m_isExecuting; } inline bool getExecutingState() { return m_isExecuting; }
private:
Scope<Environment> m_enviroment;
Scope<VoxelWorld> m_voxelWorld;
bool m_isExecuting = false;
#ifdef DEER_RENDER #ifdef DEER_RENDER
public: public:
// This function renders with the default camera in the environment
void render(); void render();
void render(SceneCamera); void render(SceneCamera);
inline GizmoRenderer& getMainGizmoRenderer() { return m_gizmoRenderer; } inline GizmoRenderer& getMainGizmoRenderer() { return m_gizmoRenderer; }
private: private:
GizmoRenderer m_gizmoRenderer; GizmoRenderer m_gizmoRenderer;
#endif #endif
private:
Scope<Environment> m_enviroment;
Scope<VoxelWorld> m_voxelWorld;
bool m_isExecuting = false;
}; };
// Namespace to manage scenes in memory
namespace SceneDataStore { namespace SceneDataStore {
void loadScene(Scene& scene, const Path& name); void loadScene(Scene& scene, const Path& name);
void exportScene(const Scene& scene, const Path& name); void exportScene(const Scene& scene, const Path& name);

View File

@ -10,6 +10,7 @@
#include "DeerStudio/Editor/Fonts.h" #include "DeerStudio/Editor/Fonts.h"
#include "DeerStudio/Editor/GamePannel.h" #include "DeerStudio/Editor/GamePannel.h"
#include "DeerStudio/Editor/Icons.h" #include "DeerStudio/Editor/Icons.h"
#include "DeerStudio/Editor/MeshExplorer/MeshExplorer.h"
#include "DeerStudio/Editor/PropertiesPannel.h" #include "DeerStudio/Editor/PropertiesPannel.h"
#include "DeerStudio/Editor/SceneExplorer.h" #include "DeerStudio/Editor/SceneExplorer.h"
#include "DeerStudio/Editor/Terrain/TerrainEditor.h" #include "DeerStudio/Editor/Terrain/TerrainEditor.h"
@ -132,9 +133,10 @@ namespace Deer {
// ---- PANNELS ----- // ---- PANNELS -----
// sceneExplorer_onImGUI(); // sceneExplorer_onImGUI();
TreePannel::treePannel_onImGui(); TreePannel::onImgui();
PropertiesPannel::propertiesPannel_onImgui(); PropertiesPannel::onImgui();
TerrainEditor::terrainEditor_onImGui(); MeshExplorer::onImGui();
TerrainEditor::onImGui();
viewport_onImGui(); viewport_onImGui();
// ---- PANNELS ----- // ---- PANNELS -----

View File

@ -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

View File

@ -0,0 +1,7 @@
#pragma once
namespace Deer {
namespace MeshExplorer {
void onImGui();
}
} // namespace Deer

View File

@ -38,7 +38,7 @@ namespace Deer {
return state; return state;
} }
void PropertiesPannel::propertiesPannel_onImgui() { void PropertiesPannel::onImgui() {
ImGui::Begin("Properties"); ImGui::Begin("Properties");
if (ActiveEntity::count() == 0) { if (ActiveEntity::count() == 0) {

View File

@ -5,6 +5,6 @@
namespace Deer { namespace Deer {
namespace PropertiesPannel { namespace PropertiesPannel {
void propertiesPannel_onImgui(); void onImgui();
} // namespace PropertiesPannel } // namespace PropertiesPannel
} // namespace Deer } // namespace Deer

View File

@ -21,7 +21,7 @@ namespace Deer {
TerrainEditMode terrainEditMode = TerrainEditMode_Add; TerrainEditMode terrainEditMode = TerrainEditMode_Add;
} // namespace TerrainEditor } // namespace TerrainEditor
void TerrainEditor::terrainEditor_onImGui() { void TerrainEditor::onImGui() {
ImGui::Begin("Terrain Editor"); ImGui::Begin("Terrain Editor");
if (!Project::m_scene.isVoxelWorldInitialized()) { if (!Project::m_scene.isVoxelWorldInitialized()) {

View File

@ -22,10 +22,10 @@ namespace Deer {
extern uint16_t selectedVoxelID; extern uint16_t selectedVoxelID;
extern uint8_t voxelSelectMode; extern uint8_t voxelSelectMode;
extern VoxelCordinates selectedVoxelStart; extern VoxelCordinates selectedVoxelStart;
extern VoxelCordinates selectedVoxelEnd; extern VoxelCordinates selectedVoxelEnd;
void terrainEditor_onImGui(); void onImGui();
void createVoxelWorldPopup(); void createVoxelWorldPopup();
void voxelSelector(); void voxelSelector();
void voxelRay(); void voxelRay();
@ -34,5 +34,5 @@ namespace Deer {
void fill(); void fill();
void info(); void info();
void empty(); void empty();
} } // namespace TerrainEditor
} } // namespace Deer

View File

@ -20,7 +20,7 @@ namespace Deer {
Entity* m_contextMenuEntity = nullptr; Entity* m_contextMenuEntity = nullptr;
} // namespace TreePannel } // namespace TreePannel
void TreePannel::treePannel_onImGui() { void TreePannel::onImgui() {
ImGui::Begin("Tree Pannel", (bool*)0, ImGuiWindowFlags_MenuBar); ImGui::Begin("Tree Pannel", (bool*)0, ImGuiWindowFlags_MenuBar);
m_isRightClickHandled = false; m_isRightClickHandled = false;

View File

@ -2,6 +2,6 @@
namespace Deer { namespace Deer {
namespace TreePannel { namespace TreePannel {
void treePannel_onImGui(); void onImgui();
} }
} }

View File

@ -1,6 +1,6 @@
[Window][DockSpace Demo] [Window][DockSpace Demo]
Pos=0,0 Pos=0,0
Size=1628,720 Size=1280,720
Collapsed=0 Collapsed=0
[Window][Debug##Default] [Window][Debug##Default]
@ -9,47 +9,55 @@ Size=400,400
Collapsed=0 Collapsed=0
[Window][Properties] [Window][Properties]
Pos=1236,24 Pos=888,24
Size=392,696 Size=392,344
Collapsed=0 Collapsed=0
DockId=0x00000004,0 DockId=0x00000004,0
[Window][Game Window] [Window][Game Window]
Pos=368,24 Pos=368,24
Size=866,696 Size=518,344
Collapsed=0 Collapsed=0
DockId=0x00000006,1 DockId=0x00000006,1
[Window][Tree Pannel] [Window][Tree Pannel]
Pos=0,24 Pos=0,24
Size=366,696 Size=366,344
Collapsed=0 Collapsed=0
DockId=0x00000005,0 DockId=0x00000005,0
[Window][Terrain Editor] [Window][Terrain Editor]
Pos=1236,24 Pos=888,24
Size=392,696 Size=392,344
Collapsed=0 Collapsed=0
DockId=0x00000004,1 DockId=0x00000004,1
[Window][Viewport] [Window][Viewport]
Pos=368,24 Pos=368,24
Size=866,696 Size=518,344
Collapsed=0 Collapsed=0
DockId=0x00000006,0 DockId=0x00000006,0
[Window][Scene Explorer] [Window][Scene Explorer]
Pos=0,929 Pos=0,389
Size=2560,442 Size=1280,331
Collapsed=0 Collapsed=0
DockId=0x00000002,0 DockId=0x00000002,0
[Docking][Data] [Window][Mesh Explorer]
DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1628,696 Split=Y Pos=0,370
DockNode ID=0x00000001 Parent=0xA1672E74 SizeRef=2560,903 Split=X Selected=0x13926F0B Size=1280,350
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1234,779 Split=X Selected=0x13926F0B Collapsed=0
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=366,779 Selected=0xBD1B42A3 DockId=0x00000008,0
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=866,779 CentralNode=1 Selected=0x13926F0B
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=392,779 Selected=0x199AB496 [Docking][Data]
DockNode ID=0x00000002 Parent=0xA1672E74 SizeRef=2560,442 Selected=0xCF339702 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