Compare commits
4 Commits
d8627d0357
...
fef75ec64b
Author | SHA1 | Date | |
---|---|---|---|
fef75ec64b | |||
3c38e2a988 | |||
e9852fe0e7 | |||
8e202f9d59 |
@ -8,18 +8,49 @@ enum class ASSET_TYPE {
|
|||||||
Unknown = -1,
|
Unknown = -1,
|
||||||
Mesh,
|
Mesh,
|
||||||
Texture,
|
Texture,
|
||||||
Material
|
Material,
|
||||||
|
Shader,
|
||||||
|
Model,
|
||||||
|
File
|
||||||
};
|
};
|
||||||
|
|
||||||
class Asset {
|
class Asset {
|
||||||
public:
|
public:
|
||||||
Asset(const char* name): name(name) {}
|
Asset(const char* name): name(name) {}
|
||||||
uuid::v4::UUID id = uuid::v4::UUID::New();
|
|
||||||
|
|
||||||
virtual ASSET_TYPE GetType() { return ASSET_TYPE::Unknown; }
|
virtual ASSET_TYPE GetType() { return detectAssetType(); }
|
||||||
|
|
||||||
const char* GetName() const { return name.c_str(); }
|
const char* GetName() const { return name.c_str(); }
|
||||||
bool isFolder = false ;
|
void setName(std::string& name) { name = name.c_str(); }
|
||||||
|
void setFilPath(std::string& path) { file = std::filesystem::path(path); }
|
||||||
|
|
||||||
|
std::string getId() { return Id.String(); }
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
uuid::v4::UUID Id = uuid::v4::UUID::New();
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
std::filesystem::path file;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ASSET_TYPE detectAssetType() {
|
||||||
|
auto ext = (file.extension()).string();
|
||||||
|
if (ext == ".obj" || ext == ".gltf" || ext == ".fbx" || ext == ".stl") {
|
||||||
|
return ASSET_TYPE::Model;
|
||||||
|
}
|
||||||
|
else if (ext == ".yproj") {
|
||||||
|
return ASSET_TYPE::File;
|
||||||
|
}
|
||||||
|
else if (ext == ".vs" || ext == ".fs") {
|
||||||
|
return ASSET_TYPE::File;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "unknown file!" << std::endl;
|
||||||
|
return ASSET_TYPE::Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
@ -1,16 +1,51 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||||
#include "EditorWindow.h"
|
#include "EditorWindow.h"
|
||||||
#include "AssetManagement/AssetManager.h"
|
#include "AssetManagement/AssetRegistry.h"
|
||||||
|
|
||||||
class AssetFinder : EditorWindow {
|
const char* hidden_extensions [] {
|
||||||
|
".exe",
|
||||||
|
".pdb",
|
||||||
|
".idb",
|
||||||
|
".dll",
|
||||||
|
".ini"
|
||||||
|
};
|
||||||
|
|
||||||
|
class AssetFinder : public EditorWindow {
|
||||||
public:
|
public:
|
||||||
AssetFinder() : EditorWindow("Assets"),
|
AssetFinder () : EditorWindow("Assets") {}
|
||||||
folderIcon ("rsc/FolderIcon.png"),
|
AssetFinder(const std::filesystem::path& projectdirectory) : EditorWindow("Assets")
|
||||||
assetIcon ("rsc/AssetIcon.png")
|
{
|
||||||
{}
|
for (auto& dir_entry : std::filesystem::directory_iterator(projectdirectory)) {
|
||||||
|
auto filepath = dir_entry.path();
|
||||||
|
|
||||||
|
if (dir_entry.is_directory() || dir_entry.is_symlink() || dir_entry.is_socket())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool has_hidden_extension = false;
|
||||||
|
for (auto hide : hidden_extensions) {
|
||||||
|
if (filepath.extension() == hide)
|
||||||
|
{
|
||||||
|
has_hidden_extension = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_hidden_extension)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Asset asset(filepath.filename().string().c_str());
|
||||||
|
asset.setFilPath(filepath.string());
|
||||||
|
spdlog::info("Created asset: {0}", asset.GetName());
|
||||||
|
files.push_back(asset);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Draw() override {
|
void Draw() override {
|
||||||
|
|
||||||
|
//assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png");
|
||||||
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
||||||
ImGui::DragInt("Maximum Columns", &maxColumns, 1, 1, 6);
|
ImGui::DragInt("Maximum Columns", &maxColumns, 1, 1, 6);
|
||||||
if (ImGui::BeginTable("##resources", 3))
|
if (ImGui::BeginTable("##resources", 3))
|
||||||
@ -20,10 +55,10 @@ public:
|
|||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int column = 0;
|
int column = 0;
|
||||||
for (auto& asset : AssetManager::assets) {
|
for (auto& asset : files ) {
|
||||||
if (column % 3 == 0) {
|
if (column % 3 == 0) {
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
column = 0;
|
column = 0;
|
||||||
@ -32,25 +67,16 @@ public:
|
|||||||
|
|
||||||
ImGui::TableSetColumnIndex(column);
|
ImGui::TableSetColumnIndex(column);
|
||||||
|
|
||||||
if (asset.isFolder) {
|
|
||||||
ImGui::ImageButton(
|
|
||||||
(ImTextureID)folderIcon.GetID(),
|
|
||||||
ImVec2{ (float)iconSize,(float)iconSize });
|
|
||||||
ImGui::Text(asset.GetName(), row);
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ImGui::ImageButton(
|
ImGui::ImageButton(
|
||||||
(ImTextureID)assetIcon.GetID(),
|
(ImTextureID)assetIcon.GetID(),
|
||||||
ImVec2{ (float)iconSize, (float)iconSize });
|
ImVec2{ (float)iconSize, (float)iconSize });
|
||||||
ImGui::Text(asset.GetName(), row);
|
ImGui::Text(asset.GetName(), row);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
column++;
|
column++;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
@ -62,6 +88,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector <Asset> files = std::vector<Asset>();
|
||||||
|
|
||||||
int iconSize = 60;
|
int iconSize = 60;
|
||||||
int maxColumns = 3;
|
int maxColumns = 3;
|
||||||
|
|
||||||
|
@ -85,16 +85,23 @@ std::vector<YoggieEngine::Mesh> processNode(aiNode* node, const aiScene* scene)
|
|||||||
|
|
||||||
Asset ModelLoader::LoadAsset(std::filesystem::path& path) {
|
Asset ModelLoader::LoadAsset(std::filesystem::path& path) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
|
|
||||||
const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
|
||||||
aiNode* currentNode = scene->mRootNode;
|
aiNode* currentNode = scene->mRootNode;
|
||||||
|
|
||||||
spdlog::debug("Loading meshes!");
|
|
||||||
|
std::cout << "Loading meshes!" << std::endl;
|
||||||
|
|
||||||
auto meshes = processNode(currentNode, scene);
|
auto meshes = processNode(currentNode, scene);
|
||||||
|
|
||||||
|
std::cout << "Model file contained " << meshes.size() << " meshes" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Asset("Mesh");
|
return Asset("Mesh");
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
#include "AssetLoader.h"
|
#include "AssetLoader.h"
|
||||||
|
|
||||||
class ModelLoader : AssetLoader {
|
class ModelLoader : AssetLoader {
|
||||||
|
public:
|
||||||
Asset LoadAsset(std::filesystem::path& path);
|
Asset LoadAsset(std::filesystem::path& path);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
@ -1,35 +1,31 @@
|
|||||||
#include "AssetManager.h"
|
#include "AssetRegistry.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include "AssetLoaders/ModelLoader.h"
|
|
||||||
/*
|
/*
|
||||||
* this is still a very naive approach to the asset manager
|
* this is still a very naive approach to the asset manager
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void AssetManager::Init()
|
AssetRegistry::AssetRegistry()
|
||||||
{
|
{
|
||||||
// Assets = std::map<uuid::v4::UUID&, Asset>();
|
|
||||||
modelLoader = ModelLoader();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::RegisterAsset(Asset& asset)
|
|
||||||
|
void AssetRegistry::RegisterAsset(Asset& asset)
|
||||||
{
|
{
|
||||||
// Assets.try_emplace(asset.id, asset);
|
Assets.try_emplace(asset.getId() , asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AssetManager::UnregisterAsset(Asset& asset) {
|
void AssetRegistry::UnregisterAsset(Asset& asset) {
|
||||||
// auto old = Assets[asset.id];
|
Assets.erase(asset.getId());
|
||||||
// Assets[asset.id] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path assetPath)
|
YoggieEngine::Mesh* AssetRegistry::LoadFromAssetFile(const std::filesystem::path assetPath)
|
||||||
{
|
{
|
||||||
YoggieEngine::Mesh* imported = nullptr;
|
YoggieEngine::Mesh* imported = nullptr;
|
||||||
|
|
||||||
@ -89,7 +85,7 @@ YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YoggieEngine::Renderable* AssetManager::LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder)
|
YoggieEngine::Renderable* AssetRegistry::LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
@ -1,23 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Asset.h"
|
#include "Asset.h"
|
||||||
#include "AssetLoaders/ModelLoader.h"
|
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
|
|
||||||
class AssetManager {
|
class AssetRegistry {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Init();
|
AssetRegistry();
|
||||||
|
//AssetRegistry(AssetPack);
|
||||||
|
|
||||||
void RegisterAsset(Asset& asset);
|
void RegisterAsset(Asset& asset);
|
||||||
void UnregisterAsset(Asset& asset);
|
void UnregisterAsset(Asset& asset);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
|
||||||
|
|
||||||
static YoggieEngine::Mesh* LoadFromAssetFile(const std::filesystem::path assetPath);
|
static YoggieEngine::Mesh* LoadFromAssetFile(const std::filesystem::path assetPath);
|
||||||
static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder);
|
static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<uuid::v4::UUID , Asset> Assets;
|
int unique_number = 0;
|
||||||
ModelLoader modelLoader;
|
std::map<std::string , Asset> Assets = std::map<std::string, Asset> ();
|
||||||
|
|
||||||
};
|
};
|
32
Editor/src/EditorCamera.h
Normal file
32
Editor/src/EditorCamera.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||||
|
|
||||||
|
class EditorCamera : public YoggieEngine::Camera {
|
||||||
|
public:
|
||||||
|
EditorCamera () : Camera(){
|
||||||
|
Front = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
|
||||||
|
view = glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation));
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Position;
|
||||||
|
glm::vec3 Rotation;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glm::vec3 Front;
|
||||||
|
glm::vec3 Right;
|
||||||
|
glm::vec3 Up;
|
||||||
|
};
|
247
Editor/src/EditorLayer.h
Normal file
247
Editor/src/EditorLayer.h
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include <mini/ini.h>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include "AssetManagement/SceneSerializer.h"
|
||||||
|
#include "AssetManagement/AssetRegistry.h"
|
||||||
|
#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 "AssetManagement/uuid.h"
|
||||||
|
#include "Project/Settings.h"
|
||||||
|
#include "Console.h"
|
||||||
|
#include "AssetManagement/AssetLoaders/ModelLoader.h"
|
||||||
|
|
||||||
|
using namespace YoggieEngine;
|
||||||
|
class EditorLayer : public Layer {
|
||||||
|
|
||||||
|
public:
|
||||||
|
EditorLayer():
|
||||||
|
Layer(),
|
||||||
|
rc(),
|
||||||
|
sceneview(scene, Selected),
|
||||||
|
explorer(Selected, scene),
|
||||||
|
inspector (Selected)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnStartup() override {
|
||||||
|
std::string path = (std::filesystem::current_path()).string();
|
||||||
|
project.setProjectDirectory(path);
|
||||||
|
assetsView = AssetFinder(project.GetProjectDirectory());
|
||||||
|
LoadLastOrEmptyProject();
|
||||||
|
|
||||||
|
AssetRegistry assetManager = AssetRegistry();
|
||||||
|
ModelLoader modelLoader = ModelLoader();
|
||||||
|
|
||||||
|
std::cout << project.GetProjectDirectory() << std::endl;
|
||||||
|
|
||||||
|
auto latern = modelLoader.LoadAsset(std::filesystem::path("build/debug/Models/Latern.gltf"));
|
||||||
|
std::cout << "Loaded mesh: " << latern.GetName() << std::endl;
|
||||||
|
|
||||||
|
//ProjectInfo projectInfo(project);
|
||||||
|
//Settings settings = Settings();
|
||||||
|
//Console console = Console();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Selected = YoggieEngine::Entity((entt::entity)-1, &scene);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdate() override {
|
||||||
|
scene.Update();
|
||||||
|
|
||||||
|
if (sceneview.isFocused) {
|
||||||
|
UpdateSceneCamera(sceneview);
|
||||||
|
|
||||||
|
std::cout << "Scene view in Focus!\r";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OnUI() override {
|
||||||
|
{
|
||||||
|
MainMenuBar menuBar = MainMenuBar();
|
||||||
|
menuBar.ApplicationMenu(project);
|
||||||
|
menuBar.SceneMenu(project, scene);
|
||||||
|
menuBar.SelectMenu();
|
||||||
|
menuBar.WindowMenu();
|
||||||
|
menuBar.DebugMenu();
|
||||||
|
menuBar.Help();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//projectInfo.Update();
|
||||||
|
sceneview.Update();
|
||||||
|
rc.Update();
|
||||||
|
explorer.Update();
|
||||||
|
//settings.Update();
|
||||||
|
inspector.Update();
|
||||||
|
//console.Update();
|
||||||
|
|
||||||
|
assetsView.Update();
|
||||||
|
|
||||||
|
ImGui::ShowDemoWindow();
|
||||||
|
//ImGui::ShowMetricsWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OnCreate() override {
|
||||||
|
std::cout << " Layer Create!" << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDestroy() override {
|
||||||
|
std::cout << " Layer Destroy!" << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
RuntimeControls rc;
|
||||||
|
Viewport sceneview ;
|
||||||
|
SceneExplorer explorer;
|
||||||
|
Inspector inspector;
|
||||||
|
AssetFinder assetsView;
|
||||||
|
|
||||||
|
bool SimulatePhysics = true;
|
||||||
|
YoggieEngine::Entity Selected;
|
||||||
|
Project project;
|
||||||
|
Scene scene;
|
||||||
|
|
||||||
|
void LoadLastOrEmptyProject() {
|
||||||
|
// Check if there is a last known loaded project and
|
||||||
|
// load that one .
|
||||||
|
|
||||||
|
// Otherwise load no project..
|
||||||
|
// OR
|
||||||
|
// Load an empty project.
|
||||||
|
mINI::INIStructure ini;
|
||||||
|
|
||||||
|
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
||||||
|
{
|
||||||
|
mINI::INIFile file("build\\Debug\\Editor.ini");
|
||||||
|
file.read(ini);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spdlog::debug("Could not find an `Editor.ini` file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini["editor"]["openlastproject"] == "TRUE")
|
||||||
|
{
|
||||||
|
|
||||||
|
Project::LoadProject(ini["cache"]["project"], project);
|
||||||
|
LoadScene(ini["cache"]["scene"], scene);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spdlog::debug("Starting without a project. Please create one.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdateSceneCamera(Viewport& sceneview) {
|
||||||
|
const float movement_speed = 0.01f;
|
||||||
|
static float lastX = 400, lastY = 300;
|
||||||
|
const float sensitivity = 0.1;
|
||||||
|
static bool firstMouse = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
||||||
|
|
||||||
|
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), 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.Rotation.x += (xoffset / 2);
|
||||||
|
sceneview.cam.Rotation.y += (xoffset /2);
|
||||||
|
sceneview.cam.Rotation.z += 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((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
firstMouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
EditorCamera& cam = sceneview.GetCamera();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_UP))
|
||||||
|
cam.Rotation.x += movement_speed;
|
||||||
|
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_DOWN))
|
||||||
|
cam.Rotation.x -= movement_speed;
|
||||||
|
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_LEFT))
|
||||||
|
cam.Rotation.y += movement_speed;
|
||||||
|
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_RIGHT))
|
||||||
|
cam.Rotation.y -= movement_speed;
|
||||||
|
|
||||||
|
|
||||||
|
cam.Update();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
@ -1,6 +1,6 @@
|
|||||||
#include "MainMenuBar.h"
|
#include "MainMenuBar.h"
|
||||||
#include <nfd.h>
|
#include <nfd.h>
|
||||||
#include "AssetManagement/AssetManager.h"
|
#include "AssetManagement/AssetRegistry.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -19,8 +19,8 @@ void MainMenuBar::ApplicationMenu(Project& project) {
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
Project::LoadProject(path, project);
|
Project::LoadProject(path, project);
|
||||||
//AssetManager::setAssetPath(project.GetProjectDirectory());
|
//AssetRegistry::setAssetPath(project.GetProjectDirectory());
|
||||||
//AssetManager::BuildAssetView();
|
//AssetRegistry::BuildAssetView();
|
||||||
break;
|
break;
|
||||||
case(NFD_CANCEL):
|
case(NFD_CANCEL):
|
||||||
break;
|
break;
|
||||||
@ -116,7 +116,7 @@ void MainMenuBar::SceneMenu(Project& project, YoggieEngine::Scene& scene) {
|
|||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
// Import Model
|
// Import Model
|
||||||
|
|
||||||
AssetManager::LoadFromSource(
|
AssetRegistry::LoadFromSource(
|
||||||
path,
|
path,
|
||||||
"build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets"
|
"build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets"
|
||||||
);
|
);
|
||||||
@ -136,7 +136,7 @@ void MainMenuBar::SceneMenu(Project& project, YoggieEngine::Scene& scene) {
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
{
|
{
|
||||||
YoggieEngine::Mesh* importedMesh = AssetManager::LoadFromAssetFile(path);
|
YoggieEngine::Mesh* importedMesh = AssetRegistry::LoadFromAssetFile(path);
|
||||||
if (importedMesh != nullptr)
|
if (importedMesh != nullptr)
|
||||||
{
|
{
|
||||||
auto full_name = std::filesystem::path(path);
|
auto full_name = std::filesystem::path(path);
|
||||||
|
@ -1,32 +1,23 @@
|
|||||||
#include "Viewport.h"
|
#include "Viewport.h"
|
||||||
|
|
||||||
Viewport::Viewport(YoggieEngine::Scene& scene ):
|
Viewport::Viewport(YoggieEngine::Scene& scene, YoggieEngine::Entity& selected) :
|
||||||
EditorWindow("SceneView"),
|
EditorWindow("SceneView"),
|
||||||
renderer(YoggieEngine::RendererConfig{ 1200, 700, glm::vec3(0), true }),
|
renderer(YoggieEngine::RendererConfig{ 1200, 700, glm::vec3(0), true })
|
||||||
cam(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90),
|
|
||||||
scene(scene)
|
|
||||||
{
|
{
|
||||||
renderer.SetMainCamera(cam);
|
CurrentScene = &scene;
|
||||||
|
this->selected = &selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewport::Draw() {
|
void Viewport::Draw() {
|
||||||
|
|
||||||
auto group = scene.getReg().view<YoggieEngine::TransformComponent, YoggieEngine::Render3DComponent>();
|
auto group = CurrentScene->getReg().view<YoggieEngine::TransformComponent, YoggieEngine::Render3DComponent>();
|
||||||
group.each([&](auto enity, YoggieEngine::TransformComponent& t, YoggieEngine::Render3DComponent& renderComponent) {
|
group.each([&](auto enity, YoggieEngine::TransformComponent& t, YoggieEngine::Render3DComponent& renderComponent) {
|
||||||
renderer.Submit(renderComponent, t);
|
renderer.Submit(renderComponent, t);
|
||||||
});
|
});
|
||||||
|
|
||||||
cam.Update();
|
isFocused = ImGui::IsWindowFocused();
|
||||||
renderer.SetMainCamera(cam);
|
|
||||||
renderer.Render(scene);
|
|
||||||
|
|
||||||
ImVec2 WinPos = ImGui::GetWindowPos();
|
|
||||||
ImVec2 ContentRegionMin = ImGui::GetWindowContentRegionMin();
|
|
||||||
ImVec2 ContentRegionMax = ImGui::GetWindowContentRegionMax();
|
|
||||||
ImVec2 ScreenSpaceMin = { ContentRegionMin.x + WinPos.x, ContentRegionMin.y + WinPos.y };
|
|
||||||
ImVec2 ScreenSpaceMax = { ContentRegionMax.x + WinPos.x,ContentRegionMax.y + WinPos.y };
|
|
||||||
|
|
||||||
|
renderer.Render(*CurrentScene);
|
||||||
|
|
||||||
ImGui::Image(
|
ImGui::Image(
|
||||||
(void*)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(),
|
(void*)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(),
|
||||||
@ -34,16 +25,37 @@ void Viewport::Draw() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImGuizmo::Enable(true);
|
ImGuizmo::Enable(true);
|
||||||
ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y, ContentRegionMax.x, ContentRegionMax.y);
|
ImGuizmo::SetOrthographic(false);
|
||||||
|
ImGuizmo::SetDrawlist();
|
||||||
|
|
||||||
glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix);
|
float windowWidth = (float)ImGui::GetWindowWidth();
|
||||||
isFocused = ImGui::IsWindowFocused();
|
float windowHeight = (float)ImGui::GetWindowHeight();
|
||||||
|
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, windowWidth, windowHeight);
|
||||||
|
|
||||||
//ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f);
|
const auto& ProjMatrix = camera.projection;
|
||||||
//ImGuizmo::ViewManipulate(glm::value_ptr(cam.ViewMatrix), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC);
|
glm::mat4& cameraView = glm::mat4(1.0f);//glm::inverse(glm::translate(glm::mat4(1.0f) , cam.Position) * glm::toMat4(glm::quat(cam.Rotation)) );
|
||||||
|
|
||||||
|
ImGuizmo::DrawGrid(glm::value_ptr(cameraView), glm::value_ptr(ProjMatrix), glm::value_ptr(cameraDelta), 100.0f);
|
||||||
|
ImGuizmo::ViewManipulate(glm::value_ptr(cameraView), 1, ImGui::GetWindowPos(), {90,90}, 0x22CCCCCC);
|
||||||
|
|
||||||
|
|
||||||
|
if (selected == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (selected->isValid()) {
|
||||||
|
|
||||||
|
auto& tc = selected->GetComponent<YoggieEngine::TransformComponent>();
|
||||||
|
glm::mat4 transform = tc.GetTransform();
|
||||||
|
|
||||||
|
ImGuizmo::Manipulate(
|
||||||
|
glm::value_ptr(cameraView),
|
||||||
|
glm::value_ptr(ProjMatrix),
|
||||||
|
ImGuizmo::TRANSLATE, ImGuizmo::LOCAL,
|
||||||
|
glm::value_ptr(transform), nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// Matrix is the model matrix we would want to manipulate
|
|
||||||
//ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix));
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,19 +6,23 @@
|
|||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "../../libs/guizmo/ImGuizmo.h"
|
#include "../../libs/guizmo/ImGuizmo.h"
|
||||||
|
#include "../EditorCamera.h"
|
||||||
|
|
||||||
|
|
||||||
class Viewport : public EditorWindow {
|
class Viewport : public EditorWindow {
|
||||||
public:
|
public:
|
||||||
bool isFocused = false;
|
bool isFocused = false;
|
||||||
YoggieEngine::Camera cam;
|
Viewport(YoggieEngine::Scene& scene, YoggieEngine::Entity& selected);
|
||||||
|
Viewport() = default;
|
||||||
Viewport(YoggieEngine::Scene& scene);
|
|
||||||
|
|
||||||
void Draw() override;
|
void Draw() override;
|
||||||
|
|
||||||
|
EditorCamera& GetCamera(){ return camera; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
YoggieEngine::Renderer renderer;
|
YoggieEngine::Renderer renderer;
|
||||||
YoggieEngine::Scene& scene;
|
YoggieEngine::Scene* CurrentScene;
|
||||||
|
YoggieEngine::Entity* selected;
|
||||||
|
glm::mat4 cameraDelta = glm::mat4(1.0);
|
||||||
|
EditorCamera camera;
|
||||||
|
|
||||||
};
|
};
|
@ -1,20 +1,7 @@
|
|||||||
#include "../../YoggieEngine/src/EntryPoint.h"
|
#include "../../YoggieEngine/src/EntryPoint.h"
|
||||||
#include <mini/ini.h>
|
#include <stack>
|
||||||
#include <glm/glm.hpp>
|
#include "EditorLayer.h"
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include "AssetManagement/SceneSerializer.h"
|
|
||||||
#include "AssetManagement/AssetManager.h"
|
|
||||||
#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 "AssetManagement/uuid.h"
|
|
||||||
#include "Project/Settings.h"
|
|
||||||
#include "Console.h"
|
|
||||||
|
|
||||||
using namespace YoggieEngine;
|
using namespace YoggieEngine;
|
||||||
|
|
||||||
@ -24,175 +11,42 @@ public:
|
|||||||
|
|
||||||
void Run() override
|
void Run() override
|
||||||
{
|
{
|
||||||
std::string path = (std::filesystem::current_path()).string();
|
|
||||||
project.setProjectDirectory(path);
|
|
||||||
|
|
||||||
LoadLastOrEmptyProject();
|
|
||||||
|
|
||||||
//ProjectInfo projectInfo(project);
|
|
||||||
RuntimeControls rc = RuntimeControls();
|
|
||||||
|
|
||||||
Viewport sceneview = Viewport(scene);
|
|
||||||
SceneExplorer explorer(Selected, scene);
|
|
||||||
Inspector inspector = Inspector(Selected);
|
|
||||||
//Settings settings = Settings();
|
|
||||||
AssetFinder assetsView = AssetFinder();
|
|
||||||
//Console console = Console();
|
|
||||||
|
|
||||||
|
|
||||||
Selected = YoggieEngine::Entity((entt::entity) -1, &scene);
|
// Create EditorLayer
|
||||||
|
EditorLayer* firstLayer = new EditorLayer();
|
||||||
|
|
||||||
|
firstLayer->OnStartup();
|
||||||
|
|
||||||
|
|
||||||
double previous = glfwGetTime();
|
double previous = glfwGetTime();
|
||||||
double lag = 0.0;
|
double lag = 0.0;
|
||||||
while (!appWindow->WindowShouldClose())
|
while (!appWindow->WindowShouldClose()) {
|
||||||
{
|
|
||||||
PollEvents();
|
PollEvents();
|
||||||
double now = glfwGetTime();
|
double now = glfwGetTime();
|
||||||
double elapsed = now - previous;
|
double elapsed = now - previous;
|
||||||
previous = now;
|
previous = now;
|
||||||
lag += elapsed;
|
lag += elapsed;
|
||||||
|
|
||||||
scene.Update();
|
|
||||||
|
|
||||||
if (sceneview.isFocused) {
|
|
||||||
UpdateSceneCamera(sceneview);
|
|
||||||
|
|
||||||
std::cout << "Scene view in Focus!\r" ;
|
|
||||||
}
|
|
||||||
|
|
||||||
GuiBegin();
|
GuiBegin();
|
||||||
|
firstLayer->OnUpdate();
|
||||||
|
firstLayer->OnUI();
|
||||||
{
|
|
||||||
MainMenuBar menuBar = MainMenuBar();
|
|
||||||
|
|
||||||
// Show a menu bar
|
|
||||||
menuBar.ApplicationMenu(project);
|
|
||||||
menuBar.SceneMenu(project, scene);
|
|
||||||
menuBar.SelectMenu();
|
|
||||||
menuBar.WindowMenu();
|
|
||||||
menuBar.DebugMenu();
|
|
||||||
menuBar.Help();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//projectInfo.Update();
|
|
||||||
sceneview.Update();
|
|
||||||
rc.Update();
|
|
||||||
explorer.Update();
|
|
||||||
//settings.Update();
|
|
||||||
inspector.Update();
|
|
||||||
//console.Update();
|
|
||||||
|
|
||||||
assetsView.Update();
|
|
||||||
|
|
||||||
ImGui::ShowDemoWindow();
|
|
||||||
//ImGui::ShowMetricsWindow();
|
|
||||||
|
|
||||||
|
|
||||||
GuiEnd();
|
GuiEnd();
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firstLayer->OnDestroy();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LoadLastOrEmptyProject() {
|
|
||||||
// Check if there is a last known loaded project and
|
|
||||||
// load that one .
|
|
||||||
|
|
||||||
// Otherwise load no project..
|
|
||||||
// OR
|
|
||||||
// Load an empty project.
|
|
||||||
mINI::INIStructure ini;
|
|
||||||
|
|
||||||
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
|
||||||
{
|
|
||||||
mINI::INIFile file("build\\Debug\\Editor.ini");
|
|
||||||
file.read(ini);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
spdlog::debug("Could not find an `Editor.ini` file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ini["editor"]["openlastproject"] == "TRUE")
|
|
||||||
{
|
|
||||||
Project::LoadProject(ini["cache"]["project"], project);
|
|
||||||
LoadScene(ini["cache"]["scene"], scene);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
spdlog::debug("Starting without a project. Please create one.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool SimulatePhysics = true;
|
|
||||||
YoggieEngine::Entity Selected;
|
|
||||||
Project project;
|
|
||||||
Scene scene;
|
|
||||||
|
|
||||||
|
|
||||||
void UpdateSceneCamera(Viewport& sceneview) {
|
std::vector<Layer*> layers = std::vector<Layer*>();
|
||||||
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((GLFWwindow*)appWindow->GetHandle(), 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((GLFWwindow*)appWindow->GetHandle(), 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;
|
|
||||||
std::cout << "Pressed W !" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
|
|
||||||
void Application::Run() {
|
void Application::Run() {
|
||||||
std::cout << "No run function implemented!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -81,6 +81,12 @@ namespace YoggieEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::PushLayer(Layer* layer)
|
||||||
|
{
|
||||||
|
AppLayerstack.PushLayer(layer);
|
||||||
|
layer->OnAttach();
|
||||||
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "YoggieEngine.h"
|
#include "YoggieEngine.h"
|
||||||
|
#include "LayerStack.h"
|
||||||
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
@ -17,11 +18,16 @@ namespace YoggieEngine {
|
|||||||
void GuiBegin();
|
void GuiBegin();
|
||||||
void GuiEnd();
|
void GuiEnd();
|
||||||
|
|
||||||
|
void PushLayer(Layer* layer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string m_AppName;
|
std::string m_AppName;
|
||||||
NativeWindow* appWindow;
|
NativeWindow* appWindow;
|
||||||
friend class ApplicationRuntime;
|
|
||||||
|
LayerStack AppLayerstack;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include "Camera.h"
|
|
||||||
namespace YoggieEngine {
|
|
||||||
Camera::Camera(const Camera& other)
|
|
||||||
: Position(other.Position), Rotation(other.Rotation), Zoom(other.Zoom)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
|
|
||||||
: Position(position), Rotation( rotation)
|
|
||||||
{
|
|
||||||
Front = glm::vec3(0.0f, 0.0f, 1.0f);
|
|
||||||
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
|
|
||||||
Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
|
||||||
Zoom = zoom;
|
|
||||||
|
|
||||||
ProjectionMatrix = glm::perspective(glm::radians(Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
|
||||||
Update();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Camera::~Camera() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Camera::Update() {
|
|
||||||
glm::vec3 WorldUp = glm::vec3(0.0f, 1.0f, 0.0f);
|
|
||||||
|
|
||||||
glm::vec3(direction);
|
|
||||||
|
|
||||||
|
|
||||||
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
|
||||||
direction.z = sin(glm::radians(yaw));
|
|
||||||
direction.y = sin(glm::radians(pitch)) * cos(glm::radians(pitch));
|
|
||||||
Front = glm::normalize(direction);
|
|
||||||
Right = glm::normalize(glm::cross(Front, WorldUp));
|
|
||||||
Up = glm::normalize(glm::cross(Right, Front));
|
|
||||||
|
|
||||||
|
|
||||||
ViewMatrix = glm::lookAt(
|
|
||||||
Position,
|
|
||||||
Position + Front,
|
|
||||||
Up);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -2,28 +2,14 @@
|
|||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
class Camera {
|
class Camera {
|
||||||
public:
|
public:
|
||||||
|
Camera() {
|
||||||
|
|
||||||
Camera() = default;
|
}
|
||||||
Camera(const Camera& other);
|
|
||||||
Camera(glm::vec3 position, glm::vec3 rotation, float zoom);
|
|
||||||
~Camera();
|
|
||||||
|
|
||||||
void Update();
|
glm::mat4 view;
|
||||||
|
glm::mat4 projection;
|
||||||
|
|
||||||
|
|
||||||
float yaw = 180;
|
|
||||||
float pitch = 0;
|
|
||||||
float Zoom;
|
|
||||||
|
|
||||||
glm::mat4 ViewMatrix;
|
|
||||||
glm::mat4 ProjectionMatrix;
|
|
||||||
|
|
||||||
glm::vec3 Position;
|
|
||||||
glm::vec3 Rotation;
|
|
||||||
|
|
||||||
glm::vec3 Front;
|
|
||||||
glm::vec3 Right;
|
|
||||||
glm::vec3 Up;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,6 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
glGenTextures(1, &Id);
|
glGenTextures(1, &Id);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, Id);
|
glBindTexture(GL_TEXTURE_2D, Id);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
@ -22,11 +21,12 @@ namespace YoggieEngine {
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
}
|
}
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
std::cout << "Failed to load image!" << std::endl;
|
||||||
spdlog::error("Failed to load image ({0})", texturePath);
|
spdlog::error("Failed to load image ({0})", texturePath);
|
||||||
}
|
}
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
@ -245,8 +245,8 @@ void Renderer::GeometryPass() {
|
|||||||
|
|
||||||
gBufferShader.setUniformVec3("Color", command.color);
|
gBufferShader.setUniformVec3("Color", command.color);
|
||||||
gBufferShader.setUniformMat4("Model", command.transform.LocalTransform);
|
gBufferShader.setUniformMat4("Model", command.transform.LocalTransform);
|
||||||
gBufferShader.setUniformMat4("View", MainCamera.ViewMatrix);
|
gBufferShader.setUniformMat4("View", MainCamera.view);
|
||||||
gBufferShader.setUniformMat4("Projection", MainCamera.ProjectionMatrix);
|
gBufferShader.setUniformMat4("Projection", MainCamera.projection);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
||||||
GL_UNSIGNED_INT, NULL);
|
GL_UNSIGNED_INT, NULL);
|
||||||
@ -271,8 +271,8 @@ void Renderer::ForwardGeometryPass()
|
|||||||
|
|
||||||
forwardShader.setUniformVec3("Color", command.color);
|
forwardShader.setUniformVec3("Color", command.color);
|
||||||
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
||||||
forwardShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
forwardShader.setUniformMat4("V", MainCamera.view);
|
||||||
forwardShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
forwardShader.setUniformMat4("P", MainCamera.projection);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
||||||
GL_UNSIGNED_INT, NULL);
|
GL_UNSIGNED_INT, NULL);
|
||||||
@ -287,8 +287,8 @@ void Renderer::SkyboxPass() {
|
|||||||
// Render skybox
|
// Render skybox
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
SkyboxShader.Use();
|
SkyboxShader.Use();
|
||||||
SkyboxShader.setUniformMat4("projection", MainCamera.ProjectionMatrix);
|
SkyboxShader.setUniformMat4("projection", MainCamera.projection);
|
||||||
SkyboxShader.setUniformMat4("view", glm::mat4(glm::mat3(MainCamera.ViewMatrix))); // remove rotation from the view matrix
|
SkyboxShader.setUniformMat4("view", glm::mat4(glm::mat3(MainCamera.view))); // remove rotation from the view matrix
|
||||||
glBindVertexArray(skyboxVAO);
|
glBindVertexArray(skyboxVAO);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, sky.getID());
|
glBindTexture(GL_TEXTURE_CUBE_MAP, sky.getID());
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
@ -334,7 +334,7 @@ void Renderer::lightingPass(Scene& scene){
|
|||||||
lightnr++;
|
lightnr++;
|
||||||
});
|
});
|
||||||
|
|
||||||
lightingPassShader.setUniformVec3("viewPos", MainCamera.Position);
|
//lightingPassShader.setUniformVec3("viewPos", MainCamera.Position);
|
||||||
|
|
||||||
// render to quad
|
// render to quad
|
||||||
if (quadVAO == 0)
|
if (quadVAO == 0)
|
||||||
@ -373,8 +373,8 @@ void Renderer::BlendingPass() {
|
|||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, grassTexture.GetID());
|
glBindTexture(GL_TEXTURE_2D, grassTexture.GetID());
|
||||||
|
|
||||||
BlendingShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
BlendingShader.setUniformMat4("V", MainCamera.view);
|
||||||
BlendingShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
BlendingShader.setUniformMat4("P", MainCamera.projection);
|
||||||
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < vegetation.size(); i++) {
|
for (unsigned int i = 0; i < vegetation.size(); i++) {
|
||||||
|
29
YoggieEngine/src/Layer.h
Normal file
29
YoggieEngine/src/Layer.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Layer {
|
||||||
|
|
||||||
|
public:
|
||||||
|
~Layer() { OnDestroy(); }
|
||||||
|
Layer() { OnCreate(); }
|
||||||
|
|
||||||
|
Layer(const std::string name )
|
||||||
|
: Name(name) {}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnUpdate(){}
|
||||||
|
virtual void OnUI(){}
|
||||||
|
virtual void OnStartup(){}
|
||||||
|
|
||||||
|
virtual void OnAttach() {}
|
||||||
|
virtual void OnDetach() {}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnCreate() {}
|
||||||
|
virtual void OnDestroy(){}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::string Name;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
27
YoggieEngine/src/LayerStack.cpp
Normal file
27
YoggieEngine/src/LayerStack.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "YoggieEngine.h"
|
||||||
|
#include "LayerStack.h"
|
||||||
|
|
||||||
|
LayerStack::~LayerStack()
|
||||||
|
{
|
||||||
|
for (Layer* layer : layers) {
|
||||||
|
layer->OnDetach();
|
||||||
|
delete layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LayerStack::PushLayer(Layer* layer) {
|
||||||
|
layers.emplace(layers.begin() + insertion_index, layer);
|
||||||
|
insertion_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LayerStack::PopLayer(Layer* layer) {
|
||||||
|
auto it = std::find(layers.begin(), layers.begin() + insertion_index, layer);
|
||||||
|
if (it != layers.begin() + insertion_index) {
|
||||||
|
layer->OnDetach();
|
||||||
|
layers.erase(it);
|
||||||
|
insertion_index--;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
22
YoggieEngine/src/LayerStack.h
Normal file
22
YoggieEngine/src/LayerStack.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Layer.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class LayerStack{
|
||||||
|
public:
|
||||||
|
LayerStack() = default;
|
||||||
|
~LayerStack();
|
||||||
|
|
||||||
|
void PushLayer(Layer* layer);
|
||||||
|
void PopLayer(Layer* layer);
|
||||||
|
|
||||||
|
std::vector<Layer*>::iterator begin() { return layers.begin(); }
|
||||||
|
std::vector<Layer*>::iterator end() { return layers.end(); }
|
||||||
|
std::vector<Layer*>::reverse_iterator rbegin() { return layers.rbegin(); }
|
||||||
|
std::vector<Layer*>::reverse_iterator rend() { return layers.rend(); }
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Layer*> layers;
|
||||||
|
int insertion_index = 0;
|
||||||
|
};
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
struct IdentifierComponent {
|
struct IdentifierComponent {
|
||||||
std::string name;
|
std::string name;
|
||||||
@ -13,6 +14,12 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
glm::mat4 LocalTransform = glm::mat4(1.0f);
|
glm::mat4 LocalTransform = glm::mat4(1.0f);
|
||||||
|
|
||||||
|
glm::mat4 GetTransform() const {
|
||||||
|
glm::mat4 rotation = glm::toMat4(glm::quat(Rotation));
|
||||||
|
return glm::translate(glm::mat4(1.0f), Position) * rotation * glm::scale(glm::mat4(1.0f), Scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RelationComponent {
|
struct RelationComponent {
|
||||||
@ -58,6 +65,8 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
|
|
||||||
struct Render3DComponent {
|
struct Render3DComponent {
|
||||||
|
Renderable* renderable;
|
||||||
|
|
||||||
unsigned int VAO = 0;
|
unsigned int VAO = 0;
|
||||||
unsigned int IBO = 0;
|
unsigned int IBO = 0;
|
||||||
Mesh mesh;
|
Mesh mesh;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user