Nigel Barink
2dcc3f1803
- Added deferred rendering mode to the renderer - Added a skybox to the forward rendering mode - moved default imported assets directory (temporary fix)
223 lines
5.6 KiB
C++
223 lines
5.6 KiB
C++
#include "../../YoggieEngine/src/EntryPoint.h"
|
|
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
|
|
#include "../../YoggieEngine/src/Physics/Physics.h"
|
|
|
|
#include <nfd.h>
|
|
|
|
#include <glm/glm.hpp>
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
#include "UI/GUIRenderer.h"
|
|
#include "UI/Widgets.h"
|
|
#include "Project/Project.h"
|
|
#include "SceneSerializer.h"
|
|
#include "AssetManagement/AssetManager.h"
|
|
#include "UI/MainMenuBar.h"
|
|
const unsigned int MS_PER_UPDATE = 2;
|
|
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene);
|
|
|
|
RendererConfig EditorSceneRendererConfig{
|
|
1200, // Screen Width
|
|
700, // Screen Height
|
|
glm::vec3{0,0,0}, // Clear Color
|
|
true // Depth testing
|
|
};
|
|
|
|
glm::vec3 temp = glm::vec3(0);
|
|
Camera cam = Camera(glm::vec3(12.0f, 1.0f, 0.0f), glm::vec3(45.0f, 0.0f, 0.0f), 90);
|
|
class Editor : public Application {
|
|
public:
|
|
Editor()
|
|
: Application("Editor"),
|
|
AppWindow(1200,700),
|
|
framebuffer(new Framebuffer(1200,700)),
|
|
viewportRenderer(EditorSceneRendererConfig),
|
|
EditorGUIRenderer(AppWindow),
|
|
Selected((entt::entity)-1)
|
|
{
|
|
viewportRenderer.setCurrentFrameBuffer(*framebuffer);
|
|
}
|
|
|
|
void RenderScene() {
|
|
// submit DrawCommands for all render3DComponents
|
|
auto group = ActiveScene.getReg().view<TransformComponent, Render3DComponent>();
|
|
group.each([&](auto enity, TransformComponent& t, Render3DComponent& renderComponent) {
|
|
viewportRenderer.Submit(renderComponent, t);
|
|
});
|
|
|
|
// Render scene
|
|
viewportRenderer.Render(ActiveScene);
|
|
|
|
}
|
|
|
|
void RenderEditorGUI() {
|
|
EditorGUIRenderer.Begin();
|
|
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
|
|
|
// Show a menu bar
|
|
{
|
|
MainMenuBar menuBar = MainMenuBar();
|
|
menuBar.ApplicationMenu(CurrentProject);
|
|
menuBar.SceneMenu(CurrentProject, ActiveScene);
|
|
menuBar.SelectMenu();
|
|
menuBar.WindowMenu();
|
|
menuBar.DebugMenu();
|
|
menuBar.Help();
|
|
}
|
|
|
|
{
|
|
ProjectInfo projectInfo(*(CurrentProject.get()));
|
|
}
|
|
|
|
{
|
|
Viewport sceneview = Viewport(*framebuffer, viewportRenderer.getCamera());
|
|
}
|
|
|
|
{
|
|
RuntimeControls rc = RuntimeControls();
|
|
}
|
|
|
|
|
|
{
|
|
SceneExplorer explorer(Selected, ActiveScene);
|
|
}
|
|
|
|
|
|
{
|
|
Inspector inspector = Inspector();
|
|
if (ActiveScene.getReg().valid(Selected)) {
|
|
Entity SelectedEntity = Entity(Selected, &ActiveScene);
|
|
inspector.AddComponentDropDown(SelectedEntity);
|
|
inspector.ShowComponents(SelectedEntity);
|
|
}
|
|
}
|
|
|
|
{
|
|
Settings settings = Settings();
|
|
}
|
|
|
|
{
|
|
// AssetFinder assetsView = AssetFinder();
|
|
}
|
|
|
|
|
|
{
|
|
Console console = Console();
|
|
console.Show();
|
|
}
|
|
|
|
ImGui::ShowDemoWindow();
|
|
ImGui::ShowMetricsWindow();
|
|
EditorGUIRenderer.End();
|
|
}
|
|
|
|
void Run() override
|
|
{
|
|
CreateTestProject(CurrentProject, ActiveScene);
|
|
ActiveScene.Start();
|
|
|
|
|
|
// Create the physics engine demo!
|
|
Physics Physics;
|
|
//Physics.Demo();
|
|
|
|
double previous = glfwGetTime();
|
|
double lag = 0.0;
|
|
while (!AppWindow.WindowShouldClose())
|
|
{
|
|
|
|
double current = glfwGetTime();
|
|
double elapsed = current - previous;
|
|
previous = current;
|
|
lag += elapsed;
|
|
|
|
AppWindow.Poll();
|
|
|
|
if (SimulatePhysics)
|
|
{
|
|
Physics.Step(1.0f / 60.0f);
|
|
}
|
|
|
|
|
|
while (lag >= MS_PER_UPDATE)
|
|
{
|
|
ActiveScene.Update();
|
|
lag -= MS_PER_UPDATE;
|
|
}
|
|
|
|
|
|
|
|
RenderScene();
|
|
|
|
RenderEditorGUI();
|
|
|
|
AppWindow.SwapBuffers();
|
|
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
}
|
|
|
|
delete framebuffer;
|
|
ActiveScene.Stop();
|
|
|
|
}
|
|
|
|
|
|
private:
|
|
NativeWindow AppWindow;
|
|
|
|
Framebuffer* framebuffer;
|
|
Renderer viewportRenderer;
|
|
|
|
GUIRenderer EditorGUIRenderer;
|
|
|
|
// Editor State
|
|
bool SimulatePhysics = false;
|
|
entt::entity Selected;
|
|
|
|
std::unique_ptr<Project> CurrentProject;
|
|
Scene ActiveScene;
|
|
|
|
};
|
|
|
|
YoggieEngine::Application* CreateApplication() {
|
|
|
|
return new Editor();
|
|
|
|
}
|
|
|
|
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene ) {
|
|
project = std::make_unique<Project>();
|
|
std::string path = (std::filesystem::current_path()).string();
|
|
project.get()->setProjectDirectory(path);
|
|
|
|
AssetManager::Init();
|
|
AssetManager::setAssetPath(project.get()->GetProjectDirectory());
|
|
AssetManager::BuildAssetView();
|
|
|
|
// Create a level and load it as the current level
|
|
auto importer = ModelImporter();
|
|
|
|
// Create a cube
|
|
auto model = importer.Import("build/Debug/Models/Cube.obj");
|
|
auto cube = scene.AddEntity("Cube");
|
|
|
|
auto& render3DComponent = cube.AddComponent<Render3DComponent>();
|
|
render3DComponent.mesh = *(model->renderable->mesh);
|
|
|
|
cube.GetComponent<TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
|
|
|
|
auto cube2 = scene.AddEntity("Cube1");
|
|
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
|
|
rendercube2.mesh = *(model->renderable->mesh);
|
|
|
|
// create an ambient light source
|
|
auto light = scene.AddEntity("Light");
|
|
auto lightComponent = light.AddComponent<LightComponent>();
|
|
lightComponent.Color = glm::vec3(1.0f);
|
|
|
|
|
|
|
|
}
|