Added the basics for a scene explorer in ImGui

This commit is contained in:
Nigel Barink 2022-07-10 15:52:25 +02:00
parent 6a2e8d3b2f
commit e31fd036ea
4 changed files with 41 additions and 22 deletions

View File

@ -6,7 +6,7 @@
class Node { class Node {
public: public:
Node(const std::string& name); Node(const std::string& name);
const std::string& name; std::string name;
Node* parent; Node* parent;
std::vector<Node*> children; std::vector<Node*> children;

View File

@ -1,5 +1,32 @@
#include "GUI.h" #include "GUI.h"
void SceneExplorer(Scene& scene, std::string PanelName) {
ImGui::Begin(PanelName.c_str());
ImGui::ListBoxHeader("##ObjectList");
Node& current = scene.GetRoot();
Node* next = &current;
// Show first node
ImGui::Selectable(next->name.c_str(), true);
ImGui::Indent();
if (next->children.size() != 0) {
for (auto child : next->children)
{
std::string& name = child->name;
ImGui::Selectable(name.c_str(), false);
}
}
ImGui::ListBoxFooter();
ImGui::End();
}
void CameraTool(Camera* cam) { void CameraTool(Camera* cam) {
ImGui::Begin("Camera"); ImGui::Begin("Camera");

View File

@ -6,3 +6,4 @@ void CameraTool(Camera* camera);
void ScriptingTool(char* code); void ScriptingTool(char* code);
void transformWindow(Transform& transform, std::string PanelName); void transformWindow(Transform& transform, std::string PanelName);
void materialWindow(Material& material, std::string PanelName); void materialWindow(Material& material, std::string PanelName);
void SceneExplorer(Scene& scene, std::string PanelName);

View File

@ -20,40 +20,41 @@ const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter(); BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
Scene* Level1;
/* /*
* Runs once at startup * Runs once at startup
* - USe to initialize the game/sandbox/demo * - USe to initialize the game/sandbox/demo
*/ */
void Start() { void Start() {
// Build a basic test scene
// NOTE: This will later be done through an editor
// Create a level and load it as the current level // Create a level and load it as the current level
std::string levelName("TestLevel"); std::string levelName("Test Level");
auto Level1 = SceneManager::CreateScene(levelName); Level1 = SceneManager::CreateScene(levelName);
SceneManager::LoadScene(*Level1); SceneManager::LoadScene(*Level1);
// Create a cube node // Create a cube node
// Load a model // Load a model
// *(MI->Import("build/SandboxApplication/Debug/Models/Cube.obj")) // *(MI->Import("build/SandboxApplication/Debug/Models/Cube.obj"))
//
std::string groupName("Nested-Group"); std::string groupName("Nested-Group");
auto testGroup = new Group(groupName); auto testGroup = new Group(groupName);
Level1->GetRoot().addChild( *testGroup); Level1->GetRoot().addChild( *testGroup);
// Build a basic test scene
// NOTE: This will later be done through an editor
std::string group2Name("Nested-Group2");
auto testGroup2 = new Group(group2Name);
Level1->GetRoot().addChild(*testGroup2);
// Walk scene graph // Walk scene graph
PrintSceneTree(Level1->GetRoot(),0); PrintSceneTree(Level1->GetRoot(),0);
shader = new Shader(vertexShaderSource, fragmentShaderSource); shader = new Shader(vertexShaderSource, fragmentShaderSource);
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f); cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
memset(code, '\0', 254); memset(code, '\0', 254);
} }
@ -68,24 +69,14 @@ void ImmediateGraphicsDraw() {
// at possible GUI elements to use // at possible GUI elements to use
ImGui::ShowDemoWindow(); ImGui::ShowDemoWindow();
// Show internal BarinkEngine stats // Show internal BarinkEngine stats
ShowStats(); ShowStats();
// Show different tooling for this specific sandbox // Show different tooling for this specific sandbox
CameraTool(cam); CameraTool(cam);
ScriptingTool(code); ScriptingTool(code);
//transformWindow(Cube->transform, "Transform (Cube)"); SceneExplorer(*Level1, "Scene Explorer");
//transformWindow(Cube2->transform, "Transform (Cube2)");
//materialWindow(*matCube, "Material Cube");
//materialWindow(*matCube2, "Material Cube2");
} }
/* /*