Redering cube in editor
This commit is contained in:
@ -4,7 +4,8 @@ kind "ConsoleApp"
|
||||
buildmessage "Building editor ..."
|
||||
|
||||
links{
|
||||
"BarinkEngine"
|
||||
"BarinkEngine",
|
||||
"ImGuizmo"
|
||||
}
|
||||
|
||||
includedirs{
|
||||
@ -24,7 +25,9 @@ includedirs{
|
||||
"./../libs/glew/include",
|
||||
"./../libs/glm",
|
||||
"./../libs/ImGui",
|
||||
"./../libs/guizmo",
|
||||
|
||||
"./../libs/entt/src",
|
||||
|
||||
"./include"
|
||||
|
||||
@ -37,4 +40,5 @@ libdirs {
|
||||
files {
|
||||
"./include/*.h",
|
||||
"./src/*.cpp"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,83 +1,79 @@
|
||||
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||
#include "../../BarinkEngine/src/Scene/SceneManager.h"
|
||||
#include "../../BarinkEngine/src/Scene/SceneNodeTypes.h"
|
||||
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
|
||||
#include "../../BarinkEngine/src/Graphics/Framebuffer.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"
|
||||
/*
|
||||
* Define globals
|
||||
*/
|
||||
Shader* shader;
|
||||
|
||||
char* code = new char[254];
|
||||
|
||||
const std::string vertexShaderSource = "build/Debug/test.vs";
|
||||
const std::string fragmentShaderSource = "build/Debug/test.fs";
|
||||
|
||||
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
|
||||
Framebuffer* framebuffer;
|
||||
Scene* Level1;
|
||||
BarinkEngine::SceneObject* cube;
|
||||
Scene Level1;
|
||||
BarinkEngine::SceneObject* Model;
|
||||
Entity cube;
|
||||
|
||||
/*
|
||||
* 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
|
||||
std::string levelName("Test Level");
|
||||
Level1 = SceneManager::CreateScene(levelName);
|
||||
SceneManager::LoadScene(*Level1);
|
||||
auto importer = BarinkEngine::ModelImporter();
|
||||
|
||||
// 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);
|
||||
|
||||
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||
cube.GetComponent<BarinkEngine::TransformComponent>().transform = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0.0f, 5.0f));
|
||||
renderer.Prepare(Level1);
|
||||
|
||||
|
||||
// Create a cube node
|
||||
// create an ambient light source
|
||||
auto AmbientLight = Level1.AddEntity("AmbientLight");
|
||||
AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
||||
|
||||
cube = MI->Import("build/Debug/Models/cube.obj");
|
||||
cube->renderable->material = new Material(*shader);
|
||||
cube->renderable->material->Color = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
std::cout << "Colour attachment id; " << framebuffer->GetColourAttachment() << std::endl;
|
||||
|
||||
// What is in cube now ??
|
||||
std::cout << "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;
|
||||
std::cout << "mesh elements: " << cube->renderable->mesh->elements.size() << std::endl;
|
||||
renderer.Prepare(Level1);
|
||||
|
||||
Level1->GetRoot().addChild(*cube);
|
||||
|
||||
memset(code, '\0', 254);
|
||||
framebuffer = new Framebuffer();
|
||||
|
||||
std::cout << "Colour attachment id; " << framebuffer->GetColourAttachment() << std::endl;
|
||||
// TODO: Move to runtime/ Engine
|
||||
// NOTE: Submits should later be done through walking the sceneTree
|
||||
|
||||
renderer.Submit(cube->renderable);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||
*/
|
||||
void ImmediateGraphicsDraw()
|
||||
{
|
||||
|
||||
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||
{ ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||
|
||||
// Show a menu bar
|
||||
ImGui::BeginMainMenuBar();
|
||||
|
||||
if (ImGui::BeginMenu("Application")) {
|
||||
|
||||
if (ImGui::MenuItem("Preferences")) {
|
||||
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Exit")) {
|
||||
// TODO: Exit application
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@ -85,45 +81,43 @@ void ImmediateGraphicsDraw()
|
||||
|
||||
|
||||
// Show internal BarinkEngine stats
|
||||
ShowStats();
|
||||
//ShowStats();
|
||||
Viewport(*framebuffer , Level1);
|
||||
Inspector();
|
||||
SceneExplorer(Level1);
|
||||
Settings();
|
||||
AssetsFinder();
|
||||
Console();
|
||||
|
||||
ImGui::Begin("Viewport");
|
||||
ImGui::Image((void*)(intptr_t)framebuffer->GetColourAttachment(), ImVec2{ 800,600 });
|
||||
ImGui::End();
|
||||
|
||||
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::Begin("Camera");
|
||||
ImGui::SliderFloat("Zoom", &Zoom, 10, 190);
|
||||
ImGui::InputFloat3("Position:", &Position[0]);
|
||||
|
||||
ImGui::InputFloat3("Rotation:", &Rotation[0]);
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Scripting");
|
||||
ImGui::Text("Lua Code");
|
||||
ImGui::InputTextMultiline("##", code, 255);
|
||||
bool runCode = ImGui::Button("Run");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Scene Explorer");
|
||||
ImGui::End();
|
||||
ImGui::ShowMetricsWindow();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Render()
|
||||
{
|
||||
renderer.Render( *framebuffer, Level1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Meant for game logic ( non-physics related)
|
||||
*/
|
||||
void Update()
|
||||
{
|
||||
// glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GetId());
|
||||
|
||||
renderer.Render(*framebuffer);
|
||||
}
|
||||
|
||||
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
/*
|
||||
* Runs every physics update
|
||||
*/
|
||||
void fixed_update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -133,6 +127,4 @@ void Update()
|
||||
void Stop()
|
||||
{
|
||||
delete framebuffer;
|
||||
delete MI;
|
||||
delete shader;
|
||||
}
|
79
Editor/src/widgets/widgets.h
Normal file
79
Editor/src/widgets/widgets.h
Normal file
@ -0,0 +1,79 @@
|
||||
#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