Added a few thing , and started simplifying renderer

- Added context menu to Inspector
- Added check to see if project path exists.
- Simplifying the renderer design
This commit is contained in:
2023-05-12 22:38:10 +02:00
parent 550c1b6e5b
commit daf26c304b
9 changed files with 436 additions and 373 deletions

View File

@ -16,6 +16,10 @@ public:
AssetFinder () : EditorWindow("Assets") {}
AssetFinder(const std::filesystem::path& projectdirectory) : EditorWindow("Assets")
{
assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png");
spdlog::info("asset iconID: {0}", assetIcon.GetID());
for (auto& dir_entry : std::filesystem::directory_iterator(projectdirectory)) {
auto filepath = dir_entry.path();
@ -39,7 +43,6 @@ public:
spdlog::info("Created asset: {0}", asset.GetName());
files.push_back(asset);
assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png");
}

View File

@ -8,9 +8,7 @@ public:
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
Up = glm::vec3(0.0f, 1.0f, 0.0f);
projection = glm::perspective(glm::radians(65.0f), (800.0f / 600.0f), 0.001f, 100.0f);
view = glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation));
}
@ -19,8 +17,8 @@ public:
view = glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation));
}
glm::vec3 Position;
glm::vec3 Rotation;
glm::vec3 Position = glm::vec3(0.0f);
glm::vec3 Rotation = glm::vec3(0.0f);
private:

View File

@ -17,15 +17,34 @@
#include "IconsMaterialDesign.h"
#include "Project/Project.h"
#include <ImGuizmo.h>
#include "EditorCamera.h"
#include "../../YoggieEngine/src/Graphics/Memory/VertexArray.h"
#include "../../YoggieEngine/src/Graphics/Memory/Buffer.h"
using namespace YoggieEngine;
class EditorLayer : public Layer {
public:
EditorLayer():
EditorLayer() :
Layer(),
inspector (Selected)
Logo("rsc/Yoggie.png"),
inspector(Selected),
scene(),
renderer()
{
spdlog::info("Colour attachment id: {0}", renderer.getCurrentFrameBuffer().GetColourAttachment());
Selected = YoggieEngine::Entity((entt::entity)-1, &scene);
AssetRegistry assetManager = AssetRegistry();
// ModelLoader modelLoader = ModelLoader();
spdlog::info("{0}", project.GetProjectDirectory().string());
//auto latern = modelLoader.LoadAsset(std::filesystem::path("build/debug/Models/Latern.gltf"));
//spdlog::info("Loaded mesh: {0}", latern.GetName());
}
void OnStartup() override {
@ -33,27 +52,13 @@ public:
project.setProjectDirectory(path);
assetsView = AssetFinder(project.GetProjectDirectory());
LoadLastOrEmptyProject();
AssetRegistry assetManager = AssetRegistry();
ModelLoader modelLoader = ModelLoader();
spdlog::info( "{0}", project.GetProjectDirectory().string());
auto latern = modelLoader.LoadAsset(std::filesystem::path("build/debug/Models/Latern.gltf"));
spdlog::info( "Loaded mesh: {0}" , latern.GetName() );
cube = (ModelLoader()).LoadAsset(std::filesystem::path("build/debug/Models/cube.obj"));
//Settings settings = Settings();
//Console console = Console();
Logo = Texture("rsc/Yoggie.png", true);
Selected = YoggieEngine::Entity((entt::entity)-1, &scene);
}
glm::vec3 cameraPosition = glm::vec3(0.0f, 0.0f, -5.0f);
glm::vec3 cameraRotation = glm::vec3(0.0f);
void OnUpdate() override {
scene.Update();
/*
@ -61,13 +66,59 @@ public:
UpdateSceneCamera(sceneview);
}
*/
auto components = scene.getReg().view<Render3DComponent>();
for(auto component : components){
auto& renderComponent = YoggieEngine::Entity(component, &scene).GetComponent<Render3DComponent>();
renderComponent.mesh = cube;
if (renderComponent.VAO == 0 || renderComponent.IBO == 0) {
VertexArray va = VertexArray();
Buffer vertexBuffer = Buffer();
Buffer elementBuffer = Buffer();
va.Create();
va.Bind();
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(Vertex), false);
elementBuffer.createBuffer();
elementBuffer.Bind(true);
elementBuffer.setBufferData((void*)&renderComponent.mesh.elements[0], renderComponent.mesh.elements.size() * sizeof(unsigned int), true);
va.AttachAttribute(0, 3, sizeof(Vertex));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
va.Unbind();
vertexBuffer.Unbind(false);
elementBuffer.Unbind(true);
renderComponent.VAO = va.getID();
renderComponent.IBO = elementBuffer.getBufferID();
}
}
camera->view = glm::translate(glm::mat4(1.0f), cameraPosition) * glm::toMat4(glm::quat(cameraRotation));
renderer.Render(scene, *camera);
}
void OnUI() override {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { ImGui::GetWindowWidth(), 7 });
ImGui::BeginMainMenuBar();
int scaleFactor = 30;
@ -216,7 +267,6 @@ public:
ImGui::SameLine(ImGui::GetWindowWidth() - 120);
/*
ImGui::PopStyleColor();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.1f, 0.1f, 0.1f, 0.01f));
if (ImGui::Button(ICON_MD_MINIMIZE)) { spdlog::info("Minimize"); }
@ -268,9 +318,17 @@ public:
ImGui::End();
ImGui::Begin("SceneView");
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoTitleBar
| ImGuiWindowFlags_NoDecoration
| ImGuiWindowFlags_NoScrollbar
| ImGuiWindowFlags_NoMove
| ImGuiWindowFlags_NoCollapse;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 });
ImGui::Begin("SceneView",nullptr,viewportWindowFlags);
spdlog::info( "Editor Resolution {0}x{1}", (float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight());
//ImGui::Image((ImTextureID)gameScreen.GetID(), gameScreen.getSize());
ImGui::Image((ImTextureID)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(),
ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
ImGuizmo::Enable(true);
ImGuizmo::SetOrthographic(false);
@ -295,6 +353,15 @@ public:
*/
ImGui::End();
ImGui::PopStyleVar();
ImGui::Begin("EditorCamera");
ImGui::SliderFloat3("position", glm::value_ptr(cameraPosition), -50, 50);
ImGui::End();
ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr);
scene.getReg().each([&](entt::entity enttNumber) {
@ -302,8 +369,11 @@ public:
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
if (ImGui::Selectable(id.name.c_str(), entity == Selected)) {
Selected = YoggieEngine::Entity(enttNumber, &scene);
}
});
ImGui::End();
inspector.Update();
@ -340,7 +410,9 @@ private:
Scene scene;
char* path = nullptr;
Texture Logo;
Renderer renderer;
Camera* camera = new EditorCamera();
Mesh cube ;
void LoadLastOrEmptyProject() {
// Check if there is a last known loaded project and

View File

@ -31,6 +31,11 @@ void Project::SaveProject(std::filesystem::path path, Project& project)
void Project::LoadProject(std::filesystem::path path, Project& project)
{
if (!std::filesystem::exists(path)) {
throw std::runtime_error("Couldn't find project file!");
}
std::string YAMLProject;
std::stringstream sstream;
std::ifstream projectFile;
@ -47,7 +52,7 @@ void Project::LoadProject(std::filesystem::path path, Project& project)
// this is probably not perfect but it seems to work for now
project = node.as<Project>();
std::cout << "loading..." << project.Name << std::endl;
spdlog::info("loaded project {0}", project.Name);

View File

@ -1,5 +1,6 @@
#include "Inspector.h"
#include "../TransformVec3.h"
#include "../IconsMaterialDesign.h"
void Inspector::Draw()
{
@ -56,6 +57,28 @@ void Inspector::ShowComponents()
if (selected.HasComponent<YoggieEngine::TransformComponent>()) {
auto& transform = selected.GetComponent<YoggieEngine::TransformComponent>();
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - 20);
ImGui::Button(ICON_MD_SETTINGS, { 20,20 });
ImGui::OpenPopupOnItemClick("##myContext", ImGuiPopupFlags_MouseButtonRight);
if (ImGui::BeginPopupContextWindow("##myContext")) {
if (ImGui::MenuItem("Reset")) {
spdlog::info("Reset component");
}
if (ImGui::MenuItem("Copy Component")) {
spdlog::info("Copy component");
}
ImGui::EndPopup();
}
ImGui::PopStyleColor(3);
/*
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f);
ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f);