YoggieEngine/Editor/src/main.cpp
Nigel Barink f37175a01e 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
2022-11-03 20:33:14 +01:00

145 lines
2.9 KiB
C++

#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 "../../BarinkEngine/src/PerfCounter.cpp"
#include "../../BarinkEngine/src/Scene/Entity.h"
#include "Widgets.h"
/*
* Define globals
*/
Framebuffer* framebuffer;
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();
// Create a level and load it as the current level
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);
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");
auto light = AmbientLight.AddComponent<BarinkEngine::LightComponent>();
light.Color = glm::vec3(1.0f);
light.Strength = 1.0f;
Selected = (entt::entity) -1;
renderer.Prepare(Level1);
}
/*
* Runs every frame
* - Use to draw Immediate mode graphics (Not meant for HUD's )
*/
void ImmediateGraphicsDraw()
{ 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();
}
if (ImGui::BeginMenu("Scene")) {
if (ImGui::MenuItem("Add Entity")) {
Level1.AddEntity("New entity");
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
//ShowStats();
Viewport(*framebuffer, Level1);
SceneExplorer(Selected, Level1);
Inspector(Selected, Level1 );
Settings();
AssetsFinder();
Console();
ImGui::ShowDemoWindow();
ImGui::ShowMetricsWindow();
}
void Render()
{
renderer.Render( *framebuffer, Level1);
}
/*
* Runs every frame
* - Meant for game logic ( non-physics related)
*/
void Update()
{
}
/*
* Runs every physics update
*/
void fixed_update()
{
}
/*
* Runs at the end of the program
* - Meant for cleanup
*/
void Stop()
{
delete framebuffer;
}