Additions to editor
Entities can be selected using the scene-explorer, Components can be viewed and edited through the inspector , empty Entities can be added through the mainmenu bar
This commit is contained in:
		| @ -1,14 +1,18 @@ | ||||
| #include <glm/gtc/type_ptr.hpp> | ||||
| #include <glm/gtc/matrix_transform.hpp> | ||||
|  | ||||
| #include <imgui.h> | ||||
|  | ||||
| #include "stb_image.h" | ||||
| #include "../../libs/guizmo/ImGuizmo.h" | ||||
|  | ||||
| #include "../../BarinkEngine/src/BarinkEngine.h" | ||||
| #include "../../BarinkEngine/src/AssetManager/ModelImporter.h" | ||||
| #include "../../BarinkEngine/src/Graphics/Memory/Framebuffer.h" | ||||
| #include <imgui.h> | ||||
| #include "../../BarinkEngine/src/PerfCounter.cpp" | ||||
| #include "../../BarinkEngine/src/Scene/Entity.h" | ||||
| #include "stb_image.h" | ||||
| #include "../../libs/guizmo/ImGuizmo.h" | ||||
| #include "../../libs/glm/glm/gtc/type_ptr.hpp" | ||||
| #include <glm/gtc/matrix_transform.hpp> | ||||
| #include "widgets/widgets.h" | ||||
| #include "Widgets.h" | ||||
|  | ||||
| /* | ||||
| * Define globals | ||||
| */ | ||||
| @ -18,18 +22,17 @@ Scene Level1; | ||||
| BarinkEngine::SceneObject* Model; | ||||
| Entity cube; | ||||
|  | ||||
| entt::entity  Selected; | ||||
| /* | ||||
| * Runs once at startup | ||||
| * - USe to initialize the game/sandbox/demo | ||||
| */ | ||||
| void Start() { | ||||
|  | ||||
|  | ||||
|     auto io = ImGui::GetIO(); | ||||
|     io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18); | ||||
|   | ||||
|     framebuffer = new Framebuffer(); | ||||
|     // Build a basic test scene  | ||||
|     // NOTE: This will later be done through an editor  | ||||
|  | ||||
|  | ||||
|     // Create a level and load it as the current level | ||||
|     auto importer = BarinkEngine::ModelImporter(); | ||||
| @ -37,22 +40,27 @@ void Start() { | ||||
|     // Create a cube  | ||||
|     Model = importer.Import("build/Debug/Models/Cube.obj"); | ||||
|     cube = Level1.AddEntity("cube"); | ||||
|      | ||||
|     auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>(); | ||||
|     render3DComponent.mesh = *(Model->renderable->mesh); | ||||
|  | ||||
|     cube.GetComponent<BarinkEngine::TransformComponent>().transform = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0.0f, 5.0f)); | ||||
|     renderer.Prepare(Level1); | ||||
|     cube.GetComponent<BarinkEngine::TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f); | ||||
|      | ||||
|     auto cube2 = Level1.AddEntity("Cube1"); | ||||
|     auto& rendercube2 = cube2.AddComponent<BarinkEngine::Render3DComponent>(); | ||||
|     rendercube2.mesh = *(Model->renderable->mesh); | ||||
|  | ||||
|  | ||||
|     // create an ambient light source | ||||
|     auto AmbientLight = Level1.AddEntity("AmbientLight"); | ||||
|     AmbientLight.AddComponent<BarinkEngine::LightComponent>(); | ||||
|     auto light = AmbientLight.AddComponent<BarinkEngine::LightComponent>(); | ||||
|     light.Color = glm::vec3(1.0f); | ||||
|     light.Strength = 1.0f; | ||||
|  | ||||
|     std::cout << "Colour attachment id; " << framebuffer->GetColourAttachment() << std::endl;    | ||||
|     Selected = (entt::entity) -1; | ||||
|  | ||||
|     renderer.Prepare(Level1); | ||||
|  | ||||
|  | ||||
| } | ||||
| /* | ||||
| * Runs every frame | ||||
| @ -77,21 +85,30 @@ void ImmediateGraphicsDraw() | ||||
|         ImGui::EndMenu(); | ||||
|     } | ||||
|  | ||||
|     if (ImGui::BeginMenu("Scene")) { | ||||
|  | ||||
|  | ||||
|         if (ImGui::MenuItem("Add Entity")) { | ||||
|             Level1.AddEntity("New entity"); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         ImGui::EndMenu(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     ImGui::EndMainMenuBar(); | ||||
|  | ||||
|  | ||||
|     // Show internal BarinkEngine stats | ||||
|     //ShowStats(); | ||||
|     Viewport(*framebuffer , Level1); | ||||
|     Inspector(); | ||||
|     SceneExplorer(Level1); | ||||
|     Viewport(*framebuffer, Level1); | ||||
|     SceneExplorer(Selected, Level1); | ||||
|     Inspector(Selected, Level1 ); | ||||
|  | ||||
|     Settings(); | ||||
|     AssetsFinder(); | ||||
|     Console(); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     ImGui::ShowDemoWindow(); | ||||
|    ImGui::ShowMetricsWindow(); | ||||
|     | ||||
|  | ||||
| @ -102,14 +119,12 @@ void Render() | ||||
|     renderer.Render( *framebuffer, Level1); | ||||
| } | ||||
|  | ||||
|  | ||||
| /* | ||||
| * Runs every frame | ||||
| * - Meant for game logic ( non-physics related) | ||||
| */ | ||||
| void Update() | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| /* | ||||
|  | ||||
							
								
								
									
										135
									
								
								Editor/src/widgets.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								Editor/src/widgets.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,135 @@ | ||||
| #include "widgets.h" | ||||
| #include <iostream> | ||||
| #include "../../BarinkEngine/src/Scene/Components.h" | ||||
| #include "../../BarinkEngine/src/Scene/Entity.h" | ||||
| class Editor; | ||||
|  | ||||
| void ComponentView(const std::string& componentName, voidFunction func) | ||||
| { | ||||
|     ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None; | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); | ||||
|     ImGui::BeginChild(componentName.c_str()); | ||||
|  | ||||
|     func(); | ||||
|  | ||||
|     ImGui::EndChild(); | ||||
|     ImGui::PopStyleVar(); | ||||
| } | ||||
|  | ||||
| void Inspector(entt::entity ent , Scene& scene) { | ||||
|     ImGui::Begin("Inspector"); | ||||
|     static float Zoom = 90; | ||||
|     static glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f); | ||||
|     static glm::vec3 Rotation = glm::vec3(0.0f, 0.0f, 0.0f); | ||||
|     if (scene.getReg().valid(ent)) { | ||||
|  | ||||
|         Entity entity = Entity(ent, &scene); | ||||
|  | ||||
|         auto component = entity.GetComponent<BarinkEngine::IdentifierComponent>(); | ||||
|         ImGui::LabelText("## Name:", component.name.c_str() ); | ||||
|        | ||||
|         if (entity.HasComponent<BarinkEngine::TransformComponent>()) { | ||||
|             auto& transform = entity.GetComponent<BarinkEngine::TransformComponent>(); | ||||
|                 ImGui::DragFloat3("Position", glm::value_ptr(transform.Position) , 0.01); | ||||
|                 ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.01); | ||||
|                 ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.01, 0); | ||||
|            | ||||
|         } | ||||
|  | ||||
|         if (entity.HasComponent<BarinkEngine::LightComponent>()) { | ||||
|             auto& light = entity.GetComponent<BarinkEngine::LightComponent>(); | ||||
|             ImGui::DragFloat("Strength", &light.Strength, 0.001f); | ||||
|             ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color)); | ||||
|            | ||||
|         } | ||||
|  | ||||
|         if (entity.HasComponent <BarinkEngine::CameraComponent>()) { | ||||
|             auto& camera = entity.GetComponent<BarinkEngine::CameraComponent>(); | ||||
|             ComponentView("Camera", [] { | ||||
|                 ImGui::SliderFloat("Zoom", &Zoom, 10, 190); | ||||
|                 ImGui::InputFloat3("Position:", &Position[0]); | ||||
|                 ImGui::InputFloat3("Rotation:", &Rotation[0]); | ||||
|                 }); | ||||
|         } | ||||
|          | ||||
|         if (entity.HasComponent<BarinkEngine::ScriptComponent>()) { | ||||
|             ComponentView("Scripting", [] { | ||||
|                 ImGui::LabelText("##--", "Hello scripting"); | ||||
|                 }); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|     ImGui::End(); | ||||
|  | ||||
| } | ||||
|  | ||||
| void SceneExplorer(entt::entity& selected, Scene& scene ) | ||||
| { | ||||
|     ImGui::Begin("Scene Explorer"); | ||||
|  | ||||
|     scene.getReg().each([&](entt::entity enttNumber) { | ||||
|         Entity entity = Entity(enttNumber, &scene); | ||||
|         auto id = entity.GetComponent<BarinkEngine::IdentifierComponent>(); | ||||
|  | ||||
|             if (ImGui::Selectable(id.name.c_str(), enttNumber == selected )) { | ||||
|                 selected = enttNumber; | ||||
|             } | ||||
|  | ||||
|         }); | ||||
|  | ||||
|     ImGui::End(); | ||||
| } | ||||
|  | ||||
| void Viewport(Framebuffer& framebuffer, Scene& scene) { | ||||
|  | ||||
|     unsigned int viewportWindowFlags = ImGuiWindowFlags_NoTitleBar | ||||
|         | ImGuiWindowFlags_NoDecoration | ||||
|         | ImGuiWindowFlags_NoScrollbar | ||||
|         | ImGuiWindowFlags_NoMove | ||||
|         | ImGuiWindowFlags_NoCollapse; | ||||
|  | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 }); | ||||
|     ImGui::Begin("Viewport", false, viewportWindowFlags); | ||||
|     ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)800,(float)600 }); | ||||
|  | ||||
|     ImGuizmo::SetDrawlist(); | ||||
|     ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); | ||||
|     ImGuizmo::Enable(true); | ||||
|     auto cam = glm::mat4(1.0f); | ||||
|     auto eye = glm::vec3(0.0f); | ||||
|     auto center = glm::vec3(0.0f); | ||||
|     auto up = glm::vec3(0.0f, 1.0f, 0.0f); | ||||
|     auto view = glm::lookAt(eye, center, up); | ||||
|  | ||||
|     glm::mat4 projection = glm::perspective(glm::radians(90.0f), (800.0f / 600.0f), 0.001f, 100.0f); | ||||
|     auto transformMatrix = glm::mat4(1.0f); | ||||
|  | ||||
|     ImGuizmo::Manipulate(glm::value_ptr(view), glm::value_ptr(projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(transformMatrix)); | ||||
|  | ||||
|  | ||||
|     //ImGuizmo::Manipulate(glm::value_ptr(static_cam), glm::value_ptr(static_projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(trans)); | ||||
|     ImGuizmo::ViewManipulate(glm::value_ptr(cam), 8.0f, ImVec2{ 0.0f,0.0f }, ImVec2{ 128.0f,128.0f }, 0x10101010); | ||||
|     ImGui::End(); | ||||
|     ImGui::PopStyleVar(); | ||||
|  | ||||
| } | ||||
|  | ||||
| void Settings() { | ||||
|     ImGui::Begin("Settings"); | ||||
|     ImGui::LabelText("##title-settings", "Fine grain control over your engine... "); | ||||
|     ImGui::End(); | ||||
| } | ||||
|  | ||||
| void Console() { | ||||
|     ImGui::Begin("Console", false); | ||||
|     ImGui::Dummy(ImVec2{ 128, 128 }); | ||||
|     ImGui::End(); | ||||
| } | ||||
|  | ||||
| void AssetsFinder() { | ||||
|     ImGui::Begin("Asset-Finder", false); | ||||
|     ImGui::Dummy(ImVec2{ 128, 128 }); | ||||
|     ImGui::End(); | ||||
| } | ||||
							
								
								
									
										23
									
								
								Editor/src/widgets.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Editor/src/widgets.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | ||||
| #pragma once | ||||
| #include <glm/glm.hpp> | ||||
| #include <imgui.h> | ||||
| #include <string> | ||||
| #include "../../libs/guizmo/ImGuizmo.h" | ||||
| #include "../../BarinkEngine/src/BarinkEngine.h" | ||||
| #include <entt/entt.hpp> | ||||
| #include <entt/entity/fwd.hpp> | ||||
| typedef void ( *voidFunction ) (void); | ||||
|  | ||||
| void ComponentView(const std::string& componentName, voidFunction func); | ||||
|  | ||||
| void Inspector(entt::entity entity, Scene& scene); | ||||
|  | ||||
| void SceneExplorer(entt::entity& selected, Scene& scene); | ||||
|  | ||||
| void Viewport(Framebuffer& framebuffer, Scene& scene); | ||||
|  | ||||
| void Settings(); | ||||
|  | ||||
| void Console(); | ||||
|  | ||||
| void AssetsFinder(); | ||||
| @ -1,79 +0,0 @@ | ||||
| #pragma once | ||||
| #include <glm/glm.hpp> | ||||
| #include <imgui.h> | ||||
|  | ||||
| inline void Inspector ()  { | ||||
|     ImGui::Begin("Inspector"); | ||||
|     static float Zoom = 90; | ||||
|     static glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f); | ||||
|     static glm::vec3 Rotation = glm::vec3(0.0f, 0.0f, 0.0f); | ||||
|  | ||||
|     ImGui::BeginChild("Camera"); | ||||
|  | ||||
|     ImGui::SliderFloat("Zoom", &Zoom, 10, 190); | ||||
|     ImGui::InputFloat3("Position:", &Position[0]); | ||||
|  | ||||
|     ImGui::InputFloat3("Rotation:", &Rotation[0]); | ||||
|     ImGui::EndChild(); | ||||
|  | ||||
|  | ||||
|     ImGui::BeginChild("Scripting"); | ||||
|     ImGui::Text("Hello world!"); | ||||
|     ImGui::EndChild(); | ||||
|     ImGui::End(); | ||||
| } | ||||
|  | ||||
| inline void SceneExplorer(Scene& scene)  | ||||
| { | ||||
|  | ||||
|     ImGui::Begin("Scene Explorer"); | ||||
|  | ||||
|     scene.getReg().each([&](auto entity) { | ||||
|         auto id = scene.getReg().get<BarinkEngine::IdentifierComponent>(entity); | ||||
|         ImGui::LabelText("##myObject", "%s", id.name.c_str()); | ||||
|         }); | ||||
|  | ||||
|  | ||||
|     ImGui::End(); | ||||
| } | ||||
|  | ||||
| inline void Viewport(Framebuffer& framebuffer , Scene& scene ) { | ||||
|  | ||||
|     unsigned int viewportWindowFlags = ImGuiWindowFlags_NoTitleBar  | ||||
|         | ImGuiWindowFlags_NoDecoration  | ||||
|         | ImGuiWindowFlags_NoScrollbar | ||||
|         | ImGuiWindowFlags_NoMove | ||||
|         | ImGuiWindowFlags_NoCollapse; | ||||
|  | ||||
|     ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 }); | ||||
|     ImGui::Begin("Viewport", false, viewportWindowFlags ); | ||||
|     ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{ (float)800,(float)600 }); | ||||
|  | ||||
|     ImGuizmo::SetDrawlist(); | ||||
|     ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); | ||||
|     ImGuizmo::Enable(true); | ||||
|     auto cam = glm::mat4(1.0f); | ||||
|     //ImGuizmo::Manipulate(glm::value_ptr(static_cam), glm::value_ptr(static_projection), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(trans)); | ||||
|     ImGuizmo::ViewManipulate(glm::value_ptr(cam), 8.0f, ImVec2{ 0.0f,0.0f }, ImVec2{ 128.0f,128.0f }, 0x10101010); | ||||
|     ImGui::End(); | ||||
|     ImGui::PopStyleVar(); | ||||
|  | ||||
| } | ||||
|  | ||||
| inline void Settings() { | ||||
|     ImGui::Begin("Settings"); | ||||
|     ImGui::LabelText("##title-settings", "Fine grain control over your engine... "); | ||||
|     ImGui::End(); | ||||
| } | ||||
|  | ||||
| inline void Console() { | ||||
|     ImGui::Begin("Console", false ); | ||||
|     ImGui::Dummy(ImVec2{ 128, 128 }); | ||||
|     ImGui::End(); | ||||
| } | ||||
|  | ||||
| inline void AssetsFinder() { | ||||
|     ImGui::Begin("Asset-Finder", false ); | ||||
|     ImGui::Dummy(ImVec2{ 128, 128 }); | ||||
|     ImGui::End(); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user