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 {
public:
Node(const std::string& name);
const std::string& name;
std::string name;
Node* parent;
std::vector<Node*> children;

View File

@ -1,5 +1,32 @@
#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) {
ImGui::Begin("Camera");

View File

@ -6,3 +6,4 @@ void CameraTool(Camera* camera);
void ScriptingTool(char* code);
void transformWindow(Transform& transform, 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();
Scene* Level1;
/*
* Runs once at startup
* - USe to initialize the game/sandbox/demo
*/
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
std::string levelName("Test Level");
auto Level1 = SceneManager::CreateScene(levelName);
Level1 = SceneManager::CreateScene(levelName);
SceneManager::LoadScene(*Level1);
// Create a cube node
// Load a model
// *(MI->Import("build/SandboxApplication/Debug/Models/Cube.obj"))
//
std::string groupName("Nested-Group");
auto testGroup = new Group(groupName);
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
PrintSceneTree(Level1->GetRoot(),0);
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);
memset(code, '\0', 254);
}
@ -68,24 +69,14 @@ void ImmediateGraphicsDraw() {
// at possible GUI elements to use
ImGui::ShowDemoWindow();
// Show internal BarinkEngine stats
ShowStats();
// Show different tooling for this specific sandbox
CameraTool(cam);
ScriptingTool(code);
//transformWindow(Cube->transform, "Transform (Cube)");
//transformWindow(Cube2->transform, "Transform (Cube2)");
//materialWindow(*matCube, "Material Cube");
//materialWindow(*matCube2, "Material Cube2");
SceneExplorer(*Level1, "Scene Explorer");
}
/*