2022-11-12 15:57:34 +00:00
|
|
|
#include "../../YoggieEngine/src/EntryPoint.h"
|
2022-11-12 21:40:36 +00:00
|
|
|
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
|
2022-11-05 19:50:35 +00:00
|
|
|
|
2022-11-05 18:14:23 +00:00
|
|
|
#include <nfd.h>
|
|
|
|
|
2022-11-05 19:50:35 +00:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
#include "UI/GUIRenderer.h"
|
2022-11-05 18:14:23 +00:00
|
|
|
#include "UI/Widgets.h"
|
2022-11-10 20:51:11 +00:00
|
|
|
#include "Project/Project.h"
|
2022-11-05 18:14:23 +00:00
|
|
|
#include "SceneSerializer.h"
|
2022-11-10 20:51:11 +00:00
|
|
|
#include "AssetManagement/AssetManager.h"
|
2022-11-12 21:40:36 +00:00
|
|
|
#include "UI/MainMenuBar.h"
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
const unsigned int MS_PER_UPDATE = 2;
|
2022-11-12 21:40:36 +00:00
|
|
|
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
class Editor : public Application {
|
|
|
|
public:
|
|
|
|
Editor() : Application("Editor") {}
|
2022-11-12 21:40:36 +00:00
|
|
|
|
2022-11-05 18:14:23 +00:00
|
|
|
void Run() override
|
|
|
|
{
|
2022-11-12 21:40:36 +00:00
|
|
|
auto NativeEditorWindow = NativeWindow(1200, 700);
|
|
|
|
//auto renderer = Renderer();
|
|
|
|
auto GuiRenderer = GUIRenderer(NativeEditorWindow);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
Selected = (entt::entity)-1;
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
CreateTestProject(CurrentProject, ActiveScene);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
ActiveScene.Start();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
double previous = glfwGetTime();
|
|
|
|
double lag = 0.0;
|
|
|
|
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
while (!NativeEditorWindow.WindowShouldClose())
|
2022-11-05 18:14:23 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
double current = glfwGetTime();
|
|
|
|
double elapsed = current - previous;
|
|
|
|
previous = current;
|
|
|
|
lag += elapsed;
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
NativeEditorWindow.Poll();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
while (lag >= MS_PER_UPDATE)
|
|
|
|
{
|
2022-11-12 21:40:36 +00:00
|
|
|
ActiveScene.Update();
|
2022-11-05 18:14:23 +00:00
|
|
|
lag -= MS_PER_UPDATE;
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
// renderer.Render(framebuffer, ActiveScene);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
GuiRenderer.Begin();
|
|
|
|
RenderGUI();
|
|
|
|
GuiRenderer.End();
|
|
|
|
|
|
|
|
NativeEditorWindow.SwapBuffers();
|
2022-11-05 18:14:23 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
ActiveScene.Stop();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
|
2022-11-05 18:14:23 +00:00
|
|
|
void RenderGUI() {
|
|
|
|
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
|
|
|
|
|
|
|
// Show a menu bar
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
MainMenuBar menuBar= MainMenuBar();
|
|
|
|
menuBar.ApplicationMenu(CurrentProject);
|
|
|
|
menuBar.SceneMenu(CurrentProject, ActiveScene);
|
2022-11-05 18:14:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
ProjectInfo projectInfo(*(CurrentProject.get()));
|
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
Viewport sceneview = Viewport(ActiveScene);
|
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
SceneExplorer explorer(Selected, ActiveScene);
|
|
|
|
}
|
2022-11-10 20:51:11 +00:00
|
|
|
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
Inspector inspector = Inspector();
|
|
|
|
if (ActiveScene.getReg().valid(Selected)) {
|
|
|
|
Entity SelectedEntity = Entity(Selected, &ActiveScene);
|
|
|
|
inspector.AddComponentDropDown(SelectedEntity);
|
|
|
|
inspector.ShowComponents(SelectedEntity);
|
2022-11-10 20:51:11 +00:00
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
Settings();
|
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
AssetFinder assetsView = AssetFinder();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
Console console = Console();
|
|
|
|
console.Show();
|
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
ImGui::ShowMetricsWindow();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2022-11-12 21:40:36 +00:00
|
|
|
std::unique_ptr<Project> CurrentProject;
|
|
|
|
Scene ActiveScene;
|
|
|
|
entt::entity Selected;
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-11-12 15:57:34 +00:00
|
|
|
YoggieEngine::Application* CreateApplication() {
|
|
|
|
|
|
|
|
return new Editor();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
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);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
AssetManager::Init();
|
|
|
|
AssetManager::setAssetPath(project.get()->GetProjectDirectory());
|
|
|
|
AssetManager::BuildAssetView();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
// Create a level and load it as the current level
|
|
|
|
auto importer = ModelImporter();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
// Create a cube
|
|
|
|
auto model = importer.Import("build/Debug/Models/Cube.obj");
|
|
|
|
auto cube = scene.AddEntity("cube");
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
auto& render3DComponent = cube.AddComponent<Render3DComponent>();
|
|
|
|
render3DComponent.mesh = *(model->renderable->mesh);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
cube.GetComponent<TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
auto cube2 = scene.AddEntity("Cube1");
|
|
|
|
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
|
|
|
|
rendercube2.mesh = *(model->renderable->mesh);
|
2022-11-12 15:57:34 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
// create an ambient light source
|
|
|
|
auto AmbientLight = scene.AddEntity("AmbientLight");
|
|
|
|
auto light = AmbientLight.AddComponent<LightComponent>();
|
|
|
|
light.Color = glm::vec3(1.0f);
|
|
|
|
light.Strength = 1.0f;
|
|
|
|
}
|