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-12-24 01:10:29 +00:00
|
|
|
#include "../../YoggieEngine/src/Physics/Physics.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"
|
|
|
|
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene);
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-12-24 01:10:29 +00:00
|
|
|
RendererConfig EditorSceneRendererConfig{
|
|
|
|
1200, // Screen Width
|
|
|
|
700, // Screen Height
|
|
|
|
glm::vec3{0,0,0}, // Clear Color
|
|
|
|
true // Depth testing
|
|
|
|
};
|
|
|
|
|
2022-12-28 21:35:23 +00:00
|
|
|
glm::vec3 temp = glm::vec3(0);
|
2023-01-04 14:57:08 +00:00
|
|
|
Camera cam = Camera(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90);
|
2022-11-05 18:14:23 +00:00
|
|
|
class Editor : public Application {
|
|
|
|
public:
|
2022-12-24 01:10:29 +00:00
|
|
|
Editor()
|
|
|
|
: Application("Editor"),
|
|
|
|
AppWindow(1200,700),
|
|
|
|
framebuffer(new Framebuffer(1200,700)),
|
|
|
|
viewportRenderer(EditorSceneRendererConfig),
|
|
|
|
EditorGUIRenderer(AppWindow),
|
|
|
|
Selected((entt::entity)-1)
|
2022-11-05 18:14:23 +00:00
|
|
|
{
|
2022-12-24 01:10:29 +00:00
|
|
|
viewportRenderer.setCurrentFrameBuffer(*framebuffer);
|
|
|
|
}
|
2022-12-21 18:11:27 +00:00
|
|
|
|
2022-12-24 01:10:29 +00:00
|
|
|
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);
|
2022-12-21 18:11:27 +00:00
|
|
|
});
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-12-28 21:35:23 +00:00
|
|
|
// Render scene
|
|
|
|
viewportRenderer.Render(ActiveScene);
|
|
|
|
|
2022-11-05 18:14:23 +00:00
|
|
|
}
|
|
|
|
|
2022-12-24 01:10:29 +00:00
|
|
|
void RenderEditorGUI() {
|
|
|
|
EditorGUIRenderer.Begin();
|
2022-11-05 18:14:23 +00:00
|
|
|
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
|
|
|
|
|
|
|
// Show a menu bar
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
2022-12-24 01:10:29 +00:00
|
|
|
MainMenuBar menuBar = MainMenuBar();
|
2022-11-12 21:40:36 +00:00
|
|
|
menuBar.ApplicationMenu(CurrentProject);
|
|
|
|
menuBar.SceneMenu(CurrentProject, ActiveScene);
|
2022-12-24 01:10:29 +00:00
|
|
|
menuBar.SelectMenu();
|
2022-12-24 01:00:11 +00:00
|
|
|
menuBar.WindowMenu();
|
|
|
|
menuBar.DebugMenu();
|
|
|
|
menuBar.Help();
|
2022-11-05 18:14:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
2022-12-24 01:10:29 +00:00
|
|
|
ProjectInfo projectInfo(*(CurrentProject.get()));
|
2022-11-12 21:40:36 +00:00
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
2022-12-24 01:10:29 +00:00
|
|
|
Viewport sceneview = Viewport(*framebuffer, viewportRenderer.getCamera());
|
2022-11-12 21:40:36 +00:00
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-12-24 01:10:29 +00:00
|
|
|
{
|
|
|
|
RuntimeControls rc = RuntimeControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-12-24 01:10:29 +00:00
|
|
|
Settings settings = Settings();
|
2022-11-12 21:40:36 +00:00
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
2022-12-24 01:10:29 +00:00
|
|
|
// AssetFinder assetsView = AssetFinder();
|
2022-11-12 21:40:36 +00:00
|
|
|
}
|
2022-12-24 01:10:29 +00:00
|
|
|
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
{
|
|
|
|
Console console = Console();
|
|
|
|
console.Show();
|
|
|
|
}
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
ImGui::ShowMetricsWindow();
|
2022-12-24 01:10:29 +00:00
|
|
|
EditorGUIRenderer.End();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Run() override
|
|
|
|
{
|
|
|
|
CreateTestProject(CurrentProject, ActiveScene);
|
|
|
|
ActiveScene.Start();
|
|
|
|
|
|
|
|
|
|
|
|
// Create the physics engine demo!
|
|
|
|
Physics Physics;
|
2023-01-04 14:57:08 +00:00
|
|
|
Physics.Demo();
|
|
|
|
/*Physics.EnableDebugVisuals();
|
|
|
|
Physics.Step(0);
|
|
|
|
Physics.SubmitMesh();
|
|
|
|
*/
|
2022-12-24 01:10:29 +00:00
|
|
|
|
|
|
|
double previous = glfwGetTime();
|
|
|
|
double lag = 0.0;
|
|
|
|
while (!AppWindow.WindowShouldClose())
|
|
|
|
{
|
|
|
|
|
|
|
|
double current = glfwGetTime();
|
|
|
|
double elapsed = current - previous;
|
|
|
|
previous = current;
|
|
|
|
lag += elapsed;
|
|
|
|
|
|
|
|
AppWindow.Poll();
|
|
|
|
|
2022-12-28 21:35:23 +00:00
|
|
|
|
2023-01-04 14:57:08 +00:00
|
|
|
Physics.Step(elapsed);
|
|
|
|
ActiveScene.Update();
|
|
|
|
|
2022-12-24 01:10:29 +00:00
|
|
|
RenderScene();
|
2023-01-04 14:57:08 +00:00
|
|
|
/*Physics.DebugRender(*framebuffer);*/
|
2022-12-24 01:10:29 +00:00
|
|
|
|
|
|
|
RenderEditorGUI();
|
|
|
|
|
|
|
|
AppWindow.SwapBuffers();
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
delete framebuffer;
|
|
|
|
ActiveScene.Stop();
|
2022-11-05 18:14:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2022-12-24 01:10:29 +00:00
|
|
|
NativeWindow AppWindow;
|
|
|
|
|
|
|
|
Framebuffer* framebuffer;
|
|
|
|
Renderer viewportRenderer;
|
|
|
|
|
|
|
|
GUIRenderer EditorGUIRenderer;
|
|
|
|
|
|
|
|
// Editor State
|
2023-01-04 14:57:08 +00:00
|
|
|
bool SimulatePhysics = true;
|
2022-12-24 01:10:29 +00:00
|
|
|
entt::entity Selected;
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
std::unique_ptr<Project> CurrentProject;
|
|
|
|
Scene ActiveScene;
|
2022-12-21 18:11:27 +00:00
|
|
|
|
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-12-31 01:42:27 +00:00
|
|
|
|
|
|
|
// create an ambient light source
|
|
|
|
auto light = scene.AddEntity("Light");
|
|
|
|
auto lightComponent = light.AddComponent<LightComponent>();
|
|
|
|
lightComponent.Color = glm::vec3(1.0f);
|
|
|
|
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
// Create a cube
|
|
|
|
auto model = importer.Import("build/Debug/Models/Cube.obj");
|
2022-12-31 01:42:27 +00:00
|
|
|
|
2022-12-24 01:10:29 +00:00
|
|
|
auto cube = scene.AddEntity("Cube");
|
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-12-31 01:42:27 +00:00
|
|
|
auto cube2 = scene.AddEntity("Cube2");
|
2022-11-12 21:40:36 +00:00
|
|
|
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
|
|
|
|
rendercube2.mesh = *(model->renderable->mesh);
|
2022-12-31 01:42:27 +00:00
|
|
|
auto relationcube = cube.AddComponent<RelationComponent>(cube2);
|
|
|
|
|
2023-01-04 14:57:08 +00:00
|
|
|
auto Grass = scene.AddEntity("Grass/Window-Pane");
|
|
|
|
//auto& renderGrass = Grass.AddComponent<Render3DComponent>();
|
|
|
|
|
2022-12-28 21:35:23 +00:00
|
|
|
|
|
|
|
|
2022-11-12 21:40:36 +00:00
|
|
|
}
|