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:
parent
c62f3615d4
commit
f37175a01e
@ -3,7 +3,7 @@
|
||||
#include "../Graphics/Memory/VertexArray.h"
|
||||
#include "../Graphics/Memory/Buffer.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <glm/gtc/type_precision.hpp>
|
||||
float Angle = 0.0;
|
||||
Camera cam = Camera(glm::vec3(12.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
||||
@ -63,8 +63,17 @@ void BarinkEngine::Renderer::Render(Scene& scene)
|
||||
renderComponent.shader.setUniformFloat("lighting.strength", light.Strength);
|
||||
});
|
||||
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), trans.Rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
rotation *= glm::rotate(glm::mat4(1.0f), trans.Rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotation *= glm::rotate(glm::mat4(1.0f), trans.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), trans.Position) * glm::scale(glm::mat4(1.0f), trans.Scale) *rotation;
|
||||
|
||||
|
||||
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
|
||||
renderComponent.shader.setUniformMat4("M", trans.transform);
|
||||
renderComponent.shader.setUniformMat4("M", modelMatrix);
|
||||
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||
renderComponent.shader.setUniformMat4("P", projection);
|
||||
|
||||
@ -82,7 +91,7 @@ void BarinkEngine::Renderer::Render(Framebuffer& framebuffer, Scene& scene)
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.GetId());
|
||||
|
||||
glClearColor(.5f, .0f, .5f, 1.0f);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Render(scene);
|
||||
|
@ -8,14 +8,14 @@ namespace BarinkEngine {
|
||||
};
|
||||
|
||||
struct TransformComponent {
|
||||
glm::mat4 transform = glm::mat4(1.0f);
|
||||
|
||||
glm::vec3 Position = glm::vec3(0.0f);
|
||||
glm::vec3 Rotation = glm::vec3(0.0f);
|
||||
glm::vec3 Scale = glm::vec3(1.0f);
|
||||
};
|
||||
|
||||
struct LightComponent {
|
||||
float Strength = 1.0f;
|
||||
glm::vec3 Color = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -24,6 +24,11 @@ namespace BarinkEngine {
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct ScriptComponent {
|
||||
std::string file; // TODO : replace with proper properties
|
||||
};
|
||||
|
||||
struct Render3DComponent {
|
||||
unsigned int VAO = 0;
|
||||
unsigned int IBO = 0;
|
||||
|
@ -2,13 +2,13 @@
|
||||
#include <entt/entt.hpp>
|
||||
class Scene;
|
||||
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity() = default;
|
||||
Entity(entt::entity e, Scene* scene);
|
||||
Entity(const Entity& other) = default;
|
||||
|
||||
|
||||
template<class T >
|
||||
T& AddComponent() {
|
||||
return m_scene->m_registry.emplace<T>(m_entity);
|
||||
@ -19,6 +19,19 @@ public:
|
||||
return m_scene->m_registry.get<T>(m_entity);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool HasComponent() {
|
||||
return m_scene->getReg().all_of<T>(m_entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// NOTE: Not Scene context aware!!
|
||||
bool operator== (Entity& other) {
|
||||
return m_entity == other.m_entity;
|
||||
}
|
||||
|
||||
private:
|
||||
entt::entity m_entity;
|
||||
Scene* m_scene;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "Components.h"
|
||||
Scene::Scene()
|
||||
{
|
||||
m_registry = entt::basic_registry();
|
||||
//m_registry = entt::basic_registry();
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
@ -21,3 +21,4 @@ Entity Scene::AddEntity(std::string name)
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user