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/Path.h"
// File to manage Assets
namespace Deer {
template <typename T>
class Asset {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Environment> m_enviroment;
Scope<VoxelWorld> 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<Environment> m_enviroment;
Scope<VoxelWorld> 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);

View File

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

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;
}
void PropertiesPannel::propertiesPannel_onImgui() {
void PropertiesPannel::onImgui() {
ImGui::Begin("Properties");
if (ActiveEntity::count() == 0) {

View File

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

View File

@ -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()) {

View File

@ -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();
}
}
} // namespace TerrainEditor
} // namespace Deer

View File

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

View File

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

View File

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