YoggieEngine/Editor/src/app.cpp

212 lines
6.4 KiB
C++
Raw Normal View History

2022-11-12 15:57:34 +00:00
#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>
2022-11-10 20:51:11 +00:00
#include "Project/Project.h"
#include "AssetManagement/SceneSerializer.h"
2022-11-10 20:51:11 +00:00
#include "AssetManagement/AssetManager.h"
2022-12-21 18:11:27 +00:00
#include "Views/Viewport.h"
#include "PropertyPanels/SceneExplorer.h"
#include "AssetManagement/AssetFinder.h"
#include "MainMenuBar.h"
#include "PropertyPanels/Inspector.h"
#include "Project/ProjectInfo.h"
#include "Runtime/RuntimeControls.h"
#include "Project/Settings.h"
#include "Console.h"
using namespace YoggieEngine;
class Editor : public Application {
public:
Editor() : Application("Editor"), Selected((entt::entity)-1){}
void Run() override
{
LoadLastOrEmptyProject();
MainMenuBar menuBar = MainMenuBar();
ProjectInfo projectInfo(project);
Viewport sceneview = Viewport(scene);
RuntimeControls rc = RuntimeControls();
SceneExplorer explorer(Selected, scene);
Inspector inspector = Inspector();
Settings settings = Settings();
// AssetFinder assetsView = AssetFinder();
Console console = Console();
double previous = glfwGetTime();
double lag = 0.0;
while (!appWindow.WindowShouldClose())
{
PollEvents();
double now = glfwGetTime();
double elapsed = now - previous ;
previous = now;
lag += elapsed;
if (sceneview.isFocused)
{
const float movement_speed = 0.1f;
static float lastX = 400, lastY = 300;
const float sensitivity = 0.1;
static bool firstMouse = true;
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
auto newX = getCursorPosX(&appWindow);
auto newY = getCursorPosY(&appWindow);
if (firstMouse)
{
lastX = newX;
lastY = newY;
firstMouse = false;
}
float xoffset = newX - lastX;
float yoffset = newY - lastY;
lastX = newX;
lastY = newY;
xoffset *= sensitivity;
yoffset *= sensitivity;
sceneview.cam.yaw += xoffset;
sceneview.cam.pitch += yoffset;
if (sceneview.cam.pitch > 89.0f)
sceneview.cam.pitch = 89.0f;
if (sceneview.cam.pitch < -89.0f)
sceneview.cam.pitch = -89.0f;
}
else if (firstMouse == false)
{
glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
firstMouse = true;
}
// Check for Camara movement input here!
if (keyIsPressed(YOGGIE_KEY_W))
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
if (keyIsPressed(YOGGIE_KEY_A))
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
if (keyIsPressed(YOGGIE_KEY_S))
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
if (keyIsPressed(YOGGIE_KEY_D))
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
}
GuiBegin();
2022-11-10 20:51:11 +00:00
// Show a menu bar
menuBar.ApplicationMenu(project);
menuBar.SceneMenu(project, scene);
menuBar.SelectMenu();
menuBar.WindowMenu();
menuBar.DebugMenu();
menuBar.Help();
if (scene.getReg().valid(Selected)) {
Entity SelectedEntity = Entity(Selected, &scene);
inspector.AddComponentDropDown(SelectedEntity);
inspector.ShowComponents(SelectedEntity);
2022-11-10 20:51:11 +00:00
}
projectInfo.Update();
sceneview.Update();
rc.Update();
explorer.Update();
settings.Update();
inspector.Update();
console.Update();
ImGui::ShowDemoWindow();
ImGui::ShowMetricsWindow();
GuiEnd();
SwapBuffers();
}
}
void LoadLastOrEmptyProject() {
// Check if there is a last known loaded project and
// load that one .
// Otherwise load no project..
// OR
// Load an empty project.
std::string path = (std::filesystem::current_path()).string();
project.setProjectDirectory(path);
AssetManager::Init();
AssetManager::setAssetPath(project.GetProjectDirectory());
AssetManager::BuildAssetView();
// Create a level and load it as the current level
auto importer = ModelImporter();
2023-01-04 14:57:08 +00:00
// create an ambient light source
auto light = scene.AddEntity("Light");
auto& lightComponent = light.AddComponent<LightComponent>();
lightComponent.Color = glm::vec3(1.0f);
// 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("Cube2");
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
rendercube2.mesh = *(model->renderable->mesh);
auto& relationcube = cube.AddComponent<RelationComponent>(cube2);
auto& rigidbodycomp = cube.AddComponent<RigidBody>();
auto& rigidbodycomp2 = cube2.AddComponent<RigidBody>();
auto Grass = scene.AddEntity("Grass/Window-Pane");
//auto& renderGrass = Grass.AddComponent<Render3DComponent>();
}
private:
2023-01-04 14:57:08 +00:00
bool SimulatePhysics = true;
entt::entity Selected;
Project project;
Scene scene;
2022-12-21 18:11:27 +00:00
};
2022-11-12 15:57:34 +00:00
YoggieEngine::Application* CreateApplication() {
return new Editor();
}