Compare commits
11 Commits
f7e087ee8d
...
main
Author | SHA1 | Date | |
---|---|---|---|
391fd5a8a8
|
|||
7349c0eb16 | |||
19b630104c | |||
7ec13a7020 | |||
4a84df7c3e | |||
a297c7cb3a | |||
8ef886df83 | |||
817d0bdca9 | |||
c640ac574b | |||
0b2148ad55 | |||
95f77209cf |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1,3 +1,4 @@
|
|||||||
*.png filter=lfs diff=lfs merge=lfs -text
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
*.webp filter=lfs diff=lfs merge=lfs -text
|
*.webp filter=lfs diff=lfs merge=lfs -text
|
||||||
*.xcf filter=lfs diff=lfs merge=lfs -text
|
*.xcf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,3 +22,6 @@ libs/physx/physx/compiler/
|
|||||||
libs/physx/physx/buildtools/
|
libs/physx/physx/buildtools/
|
||||||
libs/physx/physx/bin/
|
libs/physx/physx/bin/
|
||||||
libs/nativefiledialog/build/
|
libs/nativefiledialog/build/
|
||||||
|
.docker
|
||||||
|
|
||||||
|
**/bin/
|
||||||
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -14,6 +14,7 @@
|
|||||||
[submodule "ImGui"]
|
[submodule "ImGui"]
|
||||||
path = libs/ImGui
|
path = libs/ImGui
|
||||||
url = https://github.com/ocornut/imgui.git
|
url = https://github.com/ocornut/imgui.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "assimp"]
|
[submodule "assimp"]
|
||||||
path = libs/assimp
|
path = libs/assimp
|
||||||
url = https://github.com/assimp/assimp.git
|
url = https://github.com/assimp/assimp.git
|
||||||
@ -31,9 +32,11 @@
|
|||||||
[submodule "libs/guizmo"]
|
[submodule "libs/guizmo"]
|
||||||
path = libs/guizmo
|
path = libs/guizmo
|
||||||
url = https://github.com/CedricGuillemet/ImGuizmo.git
|
url = https://github.com/CedricGuillemet/ImGuizmo.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "libs/yaml-cpp"]
|
[submodule "libs/yaml-cpp"]
|
||||||
path = libs/yaml-cpp
|
path = libs/yaml-cpp
|
||||||
url = https://git.barink.dev/Nigel/yaml-cpp.git
|
url = https://git.barink.dev/Nigel/yaml-cpp.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "libs/nativefiledialog"]
|
[submodule "libs/nativefiledialog"]
|
||||||
path = libs/nativefiledialog
|
path = libs/nativefiledialog
|
||||||
url = https://git.barink.dev/Nigel/nativefiledialog.git
|
url = https://git.barink.dev/Nigel/nativefiledialog.git
|
||||||
@ -44,3 +47,6 @@
|
|||||||
[submodule "libs/imgui-filebrowser"]
|
[submodule "libs/imgui-filebrowser"]
|
||||||
path = libs/imgui-filebrowser
|
path = libs/imgui-filebrowser
|
||||||
url = https://github.com/AirGuanZ/imgui-filebrowser.git
|
url = https://github.com/AirGuanZ/imgui-filebrowser.git
|
||||||
|
[submodule "libs/googletest"]
|
||||||
|
path = libs/googletest
|
||||||
|
url = https://github.com/google/googletest.git
|
||||||
|
21
CmakeLists.txt
Normal file
21
CmakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
CMAKE_MINIMUM_REQUIRED (VERSION 4.0)
|
||||||
|
project(Yoggie)
|
||||||
|
set(EXPORT_COMPILE_COMMANDS_JSON ON)
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4099")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclass-struct-conversion")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||||
|
add_compile_definitions(GLFW_STATIC)
|
||||||
|
|
||||||
|
add_subdirectory(Editor)
|
||||||
|
add_subdirectory(SandboxApp)
|
||||||
|
include(libraries.cmake)
|
||||||
|
add_subdirectory(YoggieEngine)
|
||||||
|
|
||||||
|
|
1
Editor/.gitignore
vendored
Normal file
1
Editor/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
**.dll
|
17
Editor/CMakeLists.txt
Normal file
17
Editor/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
file(GLOB SOURCE_FILES "src/*.cpp")
|
||||||
|
file(GLOB HEADER_FILES "src/*.h")
|
||||||
|
add_executable(Editor ${SOURCE_FILES} "../libs/glad/src/glad.c" ${HEADER_FILES})
|
||||||
|
|
||||||
|
target_include_directories(Editor PRIVATE
|
||||||
|
"../YoggieEngine/src"
|
||||||
|
"../libs/guizmo"
|
||||||
|
)
|
||||||
|
target_link_directories(Editor PRIVATE
|
||||||
|
"../libs/ImGui/build/Release"
|
||||||
|
"../libs/guizmo/build/Release" )
|
||||||
|
target_link_libraries(Editor
|
||||||
|
thirdparty_tools
|
||||||
|
YoggieEngine
|
||||||
|
ImGui
|
||||||
|
ImGuizmo
|
||||||
|
)
|
@ -1,47 +0,0 @@
|
|||||||
project "Editor"
|
|
||||||
kind "ConsoleApp"
|
|
||||||
|
|
||||||
buildmessage "Building editor ..."
|
|
||||||
|
|
||||||
links{
|
|
||||||
"YoggieEngine",
|
|
||||||
"ImGuizmo",
|
|
||||||
"yaml-cpp",
|
|
||||||
"nfd.lib"
|
|
||||||
}
|
|
||||||
|
|
||||||
includedirs{
|
|
||||||
|
|
||||||
"../YoggieEngine/build/Debug",
|
|
||||||
|
|
||||||
-- I'd prefer if didn't need these..
|
|
||||||
-- We'll figure that out some time later
|
|
||||||
"../libs/physx/physx/include",
|
|
||||||
"../libs/physx/pxshared/include",
|
|
||||||
incfolder["lua"],
|
|
||||||
incfolder["spdlog"],
|
|
||||||
incfolder["glm"],
|
|
||||||
incfolder["assimp"],
|
|
||||||
incfolder["glad"],
|
|
||||||
incfolder["glfw"],
|
|
||||||
|
|
||||||
incfolder["imgui"],
|
|
||||||
incfolder["imguizmo"],
|
|
||||||
incfolder["entt"],
|
|
||||||
incfolder["yamlcpp"],
|
|
||||||
incfolder["nativefiledialog"],
|
|
||||||
incfolder["mINI"]
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
staticlib["yoggie"],
|
|
||||||
staticlib["nativefiledialog"]
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"../libs/glad/src/glad.c",
|
|
||||||
"./src/**.h",
|
|
||||||
"./src/**.cpp"
|
|
||||||
}
|
|
BIN
Editor/rsc/Yoggie2.jpeg
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/Yoggie2.jpeg
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -1,56 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
#include "uuid.h"
|
|
||||||
|
|
||||||
enum class ASSET_TYPE {
|
|
||||||
Unknown = -1,
|
|
||||||
Mesh,
|
|
||||||
Texture,
|
|
||||||
Material,
|
|
||||||
Shader,
|
|
||||||
Model,
|
|
||||||
File
|
|
||||||
};
|
|
||||||
|
|
||||||
class Asset {
|
|
||||||
public:
|
|
||||||
Asset(const char* name): name(name) {}
|
|
||||||
|
|
||||||
virtual ASSET_TYPE GetType() { return detectAssetType(); }
|
|
||||||
|
|
||||||
const char* GetName() const { return name.c_str(); }
|
|
||||||
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:
|
|
||||||
uuid::v4::UUID Id = uuid::v4::UUID::New();
|
|
||||||
|
|
||||||
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 {
|
|
||||||
spdlog::warn("unknown file!");
|
|
||||||
return ASSET_TYPE::Unknown;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
@ -1,103 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "EditorWindow.h"
|
|
||||||
#include "AssetManagement/AssetRegistry.h"
|
|
||||||
|
|
||||||
const char* hidden_extensions [] {
|
|
||||||
".exe",
|
|
||||||
".pdb",
|
|
||||||
".idb",
|
|
||||||
".dll",
|
|
||||||
".ini"
|
|
||||||
};
|
|
||||||
|
|
||||||
class AssetFinder : public EditorWindow {
|
|
||||||
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();
|
|
||||||
|
|
||||||
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 {
|
|
||||||
|
|
||||||
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
|
||||||
ImGui::DragInt("Maximum Columns", &maxColumns, 1, 1, 6);
|
|
||||||
if (ImGui::BeginTable("##resources", 3))
|
|
||||||
{
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int row = 0;
|
|
||||||
int column = 0;
|
|
||||||
for (auto& asset : files ) {
|
|
||||||
if (column % 3 == 0) {
|
|
||||||
ImGui::TableNextRow();
|
|
||||||
column = 0;
|
|
||||||
row++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(column);
|
|
||||||
|
|
||||||
ImGui::ImageButton(
|
|
||||||
(ImTextureID)assetIcon.GetID(),
|
|
||||||
ImVec2{ (float)iconSize, (float)iconSize });
|
|
||||||
ImGui::Text(asset.GetName(), row);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
column++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::PopStyleColor(3);
|
|
||||||
ImGui::EndTable();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector <Asset> files = std::vector<Asset>();
|
|
||||||
|
|
||||||
int iconSize = 60;
|
|
||||||
int maxColumns = 3;
|
|
||||||
|
|
||||||
YoggieEngine::Texture folderIcon;
|
|
||||||
YoggieEngine::Texture assetIcon;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <filesystem>
|
|
||||||
#include "../Asset.h"
|
|
||||||
class AssetLoader {
|
|
||||||
public:
|
|
||||||
virtual Asset LoadAsset(std::filesystem::path& path) = 0;
|
|
||||||
// virtual void PackageAsset(Asset& asset ) = 0;
|
|
||||||
|
|
||||||
};
|
|
@ -1,109 +0,0 @@
|
|||||||
#include "ModelLoader.h"
|
|
||||||
#include <assimp/Importer.hpp>
|
|
||||||
#include <assimp/postprocess.h>
|
|
||||||
#include <assimp/scene.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ProcessVertices(aiMesh* mesh, std::vector<YoggieEngine::Vertex>& out_vertices) {
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
|
||||||
YoggieEngine::Vertex v{};
|
|
||||||
|
|
||||||
glm::vec3 vector;
|
|
||||||
vector.x = mesh->mVertices[i].x;
|
|
||||||
vector.y = mesh->mVertices[i].y;
|
|
||||||
vector.z = mesh->mVertices[i].z;
|
|
||||||
|
|
||||||
v.vertices = vector;
|
|
||||||
|
|
||||||
if (mesh->mTextureCoords[0]) {
|
|
||||||
glm::vec2 texCoord;
|
|
||||||
|
|
||||||
texCoord.x = mesh->mTextureCoords[0][i].x;
|
|
||||||
texCoord.y = mesh->mTextureCoords[0][i].y;
|
|
||||||
|
|
||||||
v.uv = texCoord;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
out_vertices.push_back(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
|
||||||
aiFace face = mesh->mFaces[i];
|
|
||||||
if (face.mNumIndices < 3)
|
|
||||||
continue;
|
|
||||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
|
||||||
out_indices.push_back(face.mIndices[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
YoggieEngine::Mesh processMesh(aiMesh* mesh, const aiScene* scene) {
|
|
||||||
std::vector<unsigned int> indices;
|
|
||||||
std::vector<YoggieEngine::Vertex> vertices;
|
|
||||||
|
|
||||||
ProcessVertices(mesh, vertices);
|
|
||||||
ProcessIndices(mesh, indices);
|
|
||||||
|
|
||||||
YoggieEngine::Mesh result;
|
|
||||||
result.vertices = vertices;
|
|
||||||
result.elements = indices;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<YoggieEngine::Mesh> processNode(aiNode* node, const aiScene* scene) {
|
|
||||||
|
|
||||||
std::vector<YoggieEngine::Mesh> meshes = std::vector<YoggieEngine::Mesh>();
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
|
||||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
|
||||||
meshes.push_back(processMesh(mesh, scene));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
|
||||||
auto m2 = processNode(node->mChildren[i], scene);
|
|
||||||
|
|
||||||
for (auto m : m2) {
|
|
||||||
meshes.push_back(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return meshes;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Asset ModelLoader::LoadAsset(std::filesystem::path& path) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Assimp::Importer importer;
|
|
||||||
|
|
||||||
const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
|
||||||
|
|
||||||
aiNode* currentNode = scene->mRootNode;
|
|
||||||
|
|
||||||
|
|
||||||
spdlog::info("Loading meshes!" );
|
|
||||||
|
|
||||||
auto meshes = processNode(currentNode, scene);
|
|
||||||
|
|
||||||
spdlog::info("Model file contained {0} meshes", meshes.size() );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Asset("Mesh");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "AssetLoader.h"
|
|
||||||
|
|
||||||
class ModelLoader : AssetLoader {
|
|
||||||
public:
|
|
||||||
Asset LoadAsset(std::filesystem::path& path);
|
|
||||||
|
|
||||||
};
|
|
@ -1,139 +0,0 @@
|
|||||||
#include "AssetRegistry.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
/*
|
|
||||||
* this is still a very naive approach to the asset manager
|
|
||||||
*/
|
|
||||||
|
|
||||||
AssetRegistry::AssetRegistry()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AssetRegistry::RegisterAsset(Asset& asset)
|
|
||||||
{
|
|
||||||
Assets.try_emplace(asset.getId() , asset);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AssetRegistry::UnregisterAsset(Asset& asset) {
|
|
||||||
Assets.erase(asset.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
YoggieEngine::Mesh* AssetRegistry::LoadFromAssetFile(const std::filesystem::path assetPath)
|
|
||||||
{
|
|
||||||
YoggieEngine::Mesh* imported = nullptr;
|
|
||||||
|
|
||||||
std::ifstream AssetFile;
|
|
||||||
AssetFile.open(assetPath, std::ios::binary);
|
|
||||||
if (AssetFile.is_open()) {
|
|
||||||
|
|
||||||
char* Header = (char*)malloc(8);
|
|
||||||
unsigned long long Vsize = 0;
|
|
||||||
uint32_t Vnum = 0;
|
|
||||||
uint32_t Enum = 0;
|
|
||||||
|
|
||||||
// Read header
|
|
||||||
AssetFile.read(Header, 8);
|
|
||||||
AssetFile.read((char*)&Vsize, sizeof(unsigned long long));
|
|
||||||
AssetFile.read((char*)&Vnum, sizeof(uint32_t));
|
|
||||||
AssetFile.read((char*)&Enum, sizeof(uint32_t));
|
|
||||||
|
|
||||||
// print Header info
|
|
||||||
spdlog::info("File has header: {0}", Header);
|
|
||||||
spdlog::info ( "Vertex size: {0}", Vsize );
|
|
||||||
spdlog::info("Number of Vertices: {0}" ,Vnum );
|
|
||||||
spdlog::info ("Number of Elements: " , Enum );
|
|
||||||
free(Header);
|
|
||||||
|
|
||||||
|
|
||||||
imported = new YoggieEngine::Mesh();
|
|
||||||
// Load Vertices (Vertex + UV )
|
|
||||||
imported->vertices = std::vector < YoggieEngine::Vertex>();
|
|
||||||
for (int i = 0; i < Vnum; i++)
|
|
||||||
{
|
|
||||||
YoggieEngine::Vertex data = YoggieEngine::Vertex();
|
|
||||||
AssetFile.read((char*)&data, Vsize);
|
|
||||||
|
|
||||||
imported->vertices.push_back(data);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip x bytes
|
|
||||||
AssetFile.ignore(sizeof(char) * 3);
|
|
||||||
|
|
||||||
// Load Elements
|
|
||||||
imported->elements = std::vector<unsigned int>();
|
|
||||||
for (int i = 0; i < Enum; i++) {
|
|
||||||
unsigned int data = 0;
|
|
||||||
AssetFile.read((char*)&data, sizeof(unsigned int));
|
|
||||||
imported->elements.push_back(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
spdlog::error( "Failed ot open mesh " );
|
|
||||||
}
|
|
||||||
|
|
||||||
return imported;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
YoggieEngine::Renderable* AssetRegistry::LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder)
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
* auto model = (YoggieEngine::ModelImporter()).Import(srcPath.string());
|
|
||||||
YoggieEngine::Mesh* exportMesh = model->renderable->mesh;
|
|
||||||
std::filesystem::path MeshFileName = assetFolder / srcPath.filename().replace_extension(".mesh");
|
|
||||||
spdlog::info( "Save path: {0}" , MeshFileName );
|
|
||||||
|
|
||||||
std::ofstream meshAsset;
|
|
||||||
meshAsset.open(MeshFileName, std::ios::binary);
|
|
||||||
if (meshAsset.is_open()) {
|
|
||||||
|
|
||||||
// write a header
|
|
||||||
static const char* HEADER = "MESH";
|
|
||||||
meshAsset.write(HEADER, sizeof(HEADER));
|
|
||||||
auto Vsize = sizeof(YoggieEngine::Vertex);
|
|
||||||
spdlog::info( "size of vertex: {0}" ,Vsize );
|
|
||||||
spdlog::info("Addr of vSize: {0}" , &Vsize );
|
|
||||||
auto Vnum = exportMesh->vertices.size();
|
|
||||||
auto Enum = exportMesh->elements.size();
|
|
||||||
|
|
||||||
meshAsset.write((char*)&Vsize, sizeof(unsigned long long));
|
|
||||||
meshAsset.write((char*)&Vnum, sizeof(uint32_t));
|
|
||||||
meshAsset.write((char*)&Enum, sizeof(uint32_t));
|
|
||||||
// write all vertices
|
|
||||||
for (auto& vertice : exportMesh->vertices)
|
|
||||||
{
|
|
||||||
meshAsset.write((char*)&vertice, sizeof(vertice));
|
|
||||||
}
|
|
||||||
|
|
||||||
// write 3 x 0 byte
|
|
||||||
meshAsset.write((const char*)"\0\0\0", sizeof(char) * 3);
|
|
||||||
|
|
||||||
// write all indices
|
|
||||||
for (auto index : exportMesh->elements) {
|
|
||||||
meshAsset.write((char*)&index, sizeof(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
meshAsset.close();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
spdlog::error("Failed to create/open mesh file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return model->renderable;
|
|
||||||
|
|
||||||
*/
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include "Asset.h"
|
|
||||||
#include "uuid.h"
|
|
||||||
|
|
||||||
class AssetRegistry {
|
|
||||||
public:
|
|
||||||
|
|
||||||
AssetRegistry();
|
|
||||||
//AssetRegistry(AssetPack);
|
|
||||||
|
|
||||||
void RegisterAsset(Asset& asset);
|
|
||||||
void UnregisterAsset(Asset& asset);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Update();
|
|
||||||
|
|
||||||
|
|
||||||
static YoggieEngine::Mesh* LoadFromAssetFile(const std::filesystem::path assetPath);
|
|
||||||
static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder);
|
|
||||||
|
|
||||||
private:
|
|
||||||
int unique_number = 0;
|
|
||||||
std::map<std::string , Asset> Assets = std::map<std::string, Asset> ();
|
|
||||||
};
|
|
@ -8,22 +8,11 @@ public:
|
|||||||
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
|
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||||
Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
Up = glm::vec3(0.0f, 1.0f, 0.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(0.0f);
|
|
||||||
glm::vec3 Rotation = glm::vec3(0.0f);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 Front;
|
glm::vec3 Front;
|
||||||
glm::vec3 Right;
|
glm::vec3 Right;
|
||||||
glm::vec3 Up;
|
glm::vec3 Up;
|
||||||
|
@ -1,125 +1,47 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mini/ini.h>
|
#include <mini/ini.h>
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include <nfd.h>
|
#include <nfd.h>
|
||||||
|
|
||||||
#include "AssetManagement/SceneSerializer.h"
|
|
||||||
#include "AssetManagement/AssetRegistry.h"
|
|
||||||
#include "AssetManagement/AssetFinder.h"
|
|
||||||
#include "PropertyPanels/Inspector.h"
|
|
||||||
#include "AssetManagement/uuid.h"
|
|
||||||
#include "Project/Settings.h"
|
|
||||||
#include "Console.h"
|
|
||||||
#include "AssetManagement/AssetLoaders/ModelLoader.h"
|
|
||||||
#include "IconsMaterialDesign.h"
|
|
||||||
#include "Project/Project.h"
|
|
||||||
#include <ImGuizmo.h>
|
#include <ImGuizmo.h>
|
||||||
#include "EditorCamera.h"
|
#include <memory>
|
||||||
#include "../../YoggieEngine/src/Graphics/Memory/VertexArray.h"
|
|
||||||
#include "../../YoggieEngine/src/Graphics/Memory/Buffer.h"
|
|
||||||
|
|
||||||
|
#include "Inspector.h"
|
||||||
|
#include "Console.h"
|
||||||
|
#include "IconsMaterialDesign.h"
|
||||||
|
#include "Project.h"
|
||||||
|
#include "EditorCamera.h"
|
||||||
using namespace YoggieEngine;
|
using namespace YoggieEngine;
|
||||||
|
|
||||||
|
|
||||||
class EditorLayer : public Layer {
|
class EditorLayer : public Layer {
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EditorLayer() :
|
EditorLayer() : Layer()
|
||||||
Layer(),
|
|
||||||
Logo("rsc/Yoggie.png"),
|
|
||||||
inspector(Selected),
|
|
||||||
scene(),
|
|
||||||
renderer()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
spdlog::info("Colour attachment id: {0}", renderer.getCurrentFrameBuffer().GetColourAttachment());
|
Logo.Load("rsc/Yoggie.png");
|
||||||
|
Selected = YoggieEngine::Entity{ (entt::entity)-1, (scene.get()) };
|
||||||
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 {
|
void OnStartup() override {
|
||||||
std::string path = (std::filesystem::current_path()).string();
|
std::string path = (std::filesystem::current_path()).string();
|
||||||
project.setProjectDirectory(path);
|
scene = std::make_unique<Scene>();
|
||||||
assetsView = AssetFinder(project.GetProjectDirectory());
|
project = std::make_unique<Project>();
|
||||||
|
project.get()->setProjectDirectory(path);
|
||||||
LoadLastOrEmptyProject();
|
LoadLastOrEmptyProject();
|
||||||
cube = (ModelLoader()).LoadAsset(std::filesystem::path("build/debug/Models/cube.obj"));
|
|
||||||
//Settings settings = Settings();
|
|
||||||
//Console console = Console();
|
//Console console = Console();
|
||||||
|
|
||||||
}
|
}
|
||||||
glm::vec3 cameraPosition = glm::vec3(0.0f, 0.0f, -5.0f);
|
|
||||||
glm::vec3 cameraRotation = glm::vec3(0.0f);
|
|
||||||
void OnUpdate() override {
|
void OnUpdate() override {
|
||||||
scene.Update();
|
scene.get()->Update();
|
||||||
/*
|
renderer.get()->Render(*scene, *camera);
|
||||||
* if (Sceneview.isFocused) {
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE;
|
|
||||||
|
|
||||||
void OnUI() override {
|
void OnUI() override {
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { ImGui::GetWindowWidth(), 7 });
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { ImGui::GetWindowWidth(), 7 });
|
||||||
ImGui::BeginMainMenuBar();
|
ImGui::BeginMainMenuBar();
|
||||||
@ -212,11 +134,13 @@ public:
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
// Import Model
|
// Import Model
|
||||||
|
/*
|
||||||
AssetRegistry::LoadFromSource(
|
AssetRegistry::LoadFromSource(
|
||||||
path,
|
path,
|
||||||
"build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets"
|
"build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets"
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case(NFD_CANCEL):
|
case(NFD_CANCEL):
|
||||||
break;
|
break;
|
||||||
@ -233,15 +157,6 @@ public:
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
{
|
{
|
||||||
YoggieEngine::Mesh* importedMesh = AssetRegistry::LoadFromAssetFile(path);
|
|
||||||
if (importedMesh != nullptr)
|
|
||||||
{
|
|
||||||
auto full_name = std::filesystem::path(path);
|
|
||||||
// auto importedModel = scene.AddEntity(full_name.filename().u8string());
|
|
||||||
// auto& rendererComponent = importedModel.AddComponent<YoggieEngine::Render3DComponent>();
|
|
||||||
// rendererComponent.mesh = *importedMesh;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -268,13 +183,6 @@ public:
|
|||||||
|
|
||||||
ImGui::SameLine(ImGui::GetWindowWidth() - 120);
|
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"); }
|
|
||||||
if (ImGui::Button(ICON_MD_MAXIMIZE)) { spdlog::info("Maximize"); }
|
|
||||||
if (ImGui::Button(ICON_MD_CLOSE)) { spdlog::info("Quit"); }
|
|
||||||
*/
|
|
||||||
ImGui::PopStyleColor(1);
|
ImGui::PopStyleColor(1);
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
@ -370,9 +278,9 @@ public:
|
|||||||
| ImGuiWindowFlags_NoCollapse;
|
| ImGuiWindowFlags_NoCollapse;
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 });
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 });
|
||||||
ImGui::Begin("SceneView",nullptr,viewportWindowFlags);
|
ImGui::Begin("SceneView",nullptr,viewportWindowFlags);
|
||||||
|
// spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||||
|
SceneisFocused = ImGui::IsWindowFocused() || ImGui::IsWindowHovered();
|
||||||
ImGui::Image((ImTextureID)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(),
|
ImGui::Image((ImTextureID)(intptr_t)renderer.get()->getCurrentFrameBuffer().GetColourAttachment(),
|
||||||
ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
|
ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
|
||||||
|
|
||||||
|
|
||||||
@ -388,40 +296,44 @@ public:
|
|||||||
|
|
||||||
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||||
|
|
||||||
const auto& ProjMatrix = camera->projection;
|
const auto& ProjMatrix = camera->getProjection(ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||||
glm::mat4& cameraView = glm::inverse(((EditorCamera*)camera)->view);
|
const glm::mat4& viewMatrix = glm::inverse(camera->getTransform());
|
||||||
glm::mat4 cameraDelta = glm::mat4(1.0f);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto& tc = Selected.GetComponent<YoggieEngine::TransformComponent>();
|
auto& tc = Selected.GetComponent<YoggieEngine::TransformComponent>();
|
||||||
glm::mat4& transform = tc.GetTransform();
|
auto transform = tc.GetTransform();
|
||||||
ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(ProjMatrix), activeOperation, ImGuizmo::WORLD, glm::value_ptr(transform), nullptr, nullptr);
|
ImGuizmo::Manipulate(
|
||||||
|
glm::value_ptr(viewMatrix),
|
||||||
|
glm::value_ptr(ProjMatrix),
|
||||||
|
activeOperation, ImGuizmo::LOCAL, glm::value_ptr(transform));
|
||||||
if (ImGuizmo::IsUsing())
|
if (ImGuizmo::IsUsing())
|
||||||
|
{
|
||||||
tc.Decompose(transform);
|
tc.Decompose(transform);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
ImGui::Begin("EditorCamera");
|
ImGui::Begin("EditorCamera");
|
||||||
|
|
||||||
ImGui::SliderFloat3("position", glm::value_ptr(cameraPosition), -50, 50);
|
ImGui::SliderFloat3("position", glm::value_ptr(camera->Position), -50, 50);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr);
|
ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr);
|
||||||
scene.getReg().each([&](entt::entity enttNumber) {
|
scene.get()->getReg().each([&](entt::entity enttNumber) {
|
||||||
YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene);
|
YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &*scene.get());
|
||||||
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
|
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
|
||||||
if (ImGui::Selectable(id.name.c_str(), entity == Selected)) {
|
if (ImGui::Selectable(id.name.c_str(), entity == Selected)) {
|
||||||
Selected = YoggieEngine::Entity(enttNumber, &scene);
|
Selected = YoggieEngine::Entity(enttNumber, &*scene);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -429,13 +341,73 @@ public:
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
inspector.Update();
|
|
||||||
|
{
|
||||||
|
ImGui::Begin("Asset", nullptr);
|
||||||
|
|
||||||
|
const char* hidden_extensions[]{
|
||||||
|
".exe",
|
||||||
|
".pdb",
|
||||||
|
".idb",
|
||||||
|
".dll",
|
||||||
|
".ini"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//settings.Update();
|
std::vector <Asset> files = std::vector<Asset>();
|
||||||
//console.Update();
|
|
||||||
|
int iconSize = 60;
|
||||||
|
int maxColumns = 3;
|
||||||
|
|
||||||
|
YoggieEngine::Texture folderIcon;
|
||||||
|
YoggieEngine::Texture assetIcon;
|
||||||
|
|
||||||
|
//assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png");
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
||||||
|
ImGui::DragInt("Max. Columns", &maxColumns, 1, 1, 6);
|
||||||
|
|
||||||
|
if (ImGui::BeginTable("##Resources", 3)) {
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
int column = 0;
|
||||||
|
for (auto& asset : files) {
|
||||||
|
if (column % 3 == 0) {
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
column = 0;
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::TableSetColumnIndex(column);
|
||||||
|
|
||||||
|
ImGui::ImageButton(
|
||||||
|
(ImTextureID)assetIcon.GetID(),
|
||||||
|
ImVec2{ (float)iconSize, (float)iconSize });
|
||||||
|
ImGui::Text(asset.Handle.String().c_str(), row);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
column++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
ImGui::EndTable();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
assetsView.Update();
|
|
||||||
|
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
//ImGui::ShowMetricsWindow();
|
//ImGui::ShowMetricsWindow();
|
||||||
@ -453,19 +425,62 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool OnKey(int key, int mode) override {
|
||||||
|
float movement_speed = 0.10f;
|
||||||
|
|
||||||
|
if (SceneisFocused) {
|
||||||
|
if (key == YOGGIE_KEY_UP)
|
||||||
|
camera->Rotation.x += movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_DOWN)
|
||||||
|
camera->Rotation.x -= movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_LEFT)
|
||||||
|
camera->Rotation.y += movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_RIGHT)
|
||||||
|
camera->Rotation.y -= movement_speed;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_A)
|
||||||
|
camera->Position += glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_S)
|
||||||
|
camera->Position += glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_D)
|
||||||
|
camera->Position -= glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed;
|
||||||
|
|
||||||
|
if (key == GLFW_KEY_W)
|
||||||
|
camera->Position -= glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Inspector inspector;
|
std::unique_ptr<Inspector> inspector = std::make_unique<Inspector>(Selected);
|
||||||
AssetFinder assetsView;
|
std::unique_ptr<Renderer> renderer = std::make_unique<Renderer>();
|
||||||
|
std::unique_ptr<EditorCamera> camera = std::make_unique<EditorCamera>();
|
||||||
|
std::unique_ptr<Project> project;
|
||||||
|
std::unique_ptr<Scene> scene;
|
||||||
|
|
||||||
|
Texture Logo;
|
||||||
|
|
||||||
|
|
||||||
bool SimulatePhysics = true;
|
bool SimulatePhysics = true;
|
||||||
|
bool SceneisFocused = false;
|
||||||
|
|
||||||
YoggieEngine::Entity Selected;
|
YoggieEngine::Entity Selected;
|
||||||
Project project;
|
ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE;
|
||||||
Scene scene;
|
|
||||||
char* path = nullptr;
|
char* path = nullptr;
|
||||||
Texture Logo;
|
|
||||||
Renderer renderer;
|
|
||||||
Camera* camera = new EditorCamera();
|
|
||||||
Mesh cube ;
|
|
||||||
|
|
||||||
void LoadLastOrEmptyProject() {
|
void LoadLastOrEmptyProject() {
|
||||||
// Check if there is a last known loaded project and
|
// Check if there is a last known loaded project and
|
||||||
@ -489,8 +504,8 @@ private:
|
|||||||
if (ini["editor"]["openlastproject"] == "TRUE")
|
if (ini["editor"]["openlastproject"] == "TRUE")
|
||||||
{
|
{
|
||||||
|
|
||||||
Project::LoadProject(ini["cache"]["project"], project);
|
Project::LoadProject(ini["cache"]["project"], *project);
|
||||||
LoadScene(ini["cache"]["scene"], scene);
|
///LoadScene(ini["cache"]["scene"], scene);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -499,101 +514,4 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UpdateSceneCamera() {
|
|
||||||
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;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
@ -9,7 +9,8 @@ public:
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
ImGui::Begin(name.c_str(), false, flags);
|
|
||||||
|
ImGui::Begin(name.c_str(), nullptr, flags);
|
||||||
Draw();
|
Draw();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "Inspector.h"
|
#include "Inspector.h"
|
||||||
#include "../TransformVec3.h"
|
#include "TransformVec3.h"
|
||||||
#include "../IconsMaterialDesign.h"
|
#include "IconsMaterialDesign.h"
|
||||||
|
|
||||||
void Inspector::Draw()
|
void Inspector::Draw()
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||||
#include "../EditorWindow.h"
|
#include "EditorWindow.h"
|
||||||
|
|
||||||
typedef void (*voidFunction) (void);
|
typedef void (*voidFunction) (void);
|
||||||
|
|
@ -68,8 +68,13 @@ namespace YAML {
|
|||||||
{
|
{
|
||||||
if (!node.IsMap())
|
if (!node.IsMap())
|
||||||
return false;
|
return false;
|
||||||
rhs.setName(node["Project"].as<std::string>());
|
|
||||||
rhs.setProjectDirectory(node["Directory"].as<std::string>());
|
std::string projectName = node["Project"].as<std::string>();
|
||||||
|
rhs.setName(projectName);
|
||||||
|
|
||||||
|
|
||||||
|
std::string projectDirectory = node["Directory"].as<std::string>();
|
||||||
|
rhs.setProjectDirectory(projectDirectory);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
#include "Settings.h"
|
|
||||||
|
|
||||||
void Settings::Draw() {
|
|
||||||
ImGui::LabelText("##title-settings", "Fine grain control over the engine!");
|
|
||||||
|
|
||||||
if (ImGui::BeginCombo("Graphics API", GraphicsAPI[selectedGfxAPI])) {
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
bool isSelected = i == selectedGfxAPI;
|
|
||||||
if (ImGui::Selectable(GraphicsAPI[i], isSelected)) {
|
|
||||||
selectedGfxAPI = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSelected)
|
|
||||||
ImGui::SetItemDefaultFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::NewLine();
|
|
||||||
|
|
||||||
if (ImGui::BeginCombo("Physics Engine", PhysicsEngine[selectedPhysicsEngine])) {
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
bool isSelected = i == selectedPhysicsEngine;
|
|
||||||
if (ImGui::Selectable(PhysicsEngine[i], isSelected)) {
|
|
||||||
selectedGfxAPI = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSelected)
|
|
||||||
ImGui::SetItemDefaultFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::InputFloat3("Gravity", glm::value_ptr(Gravity));
|
|
||||||
|
|
||||||
ImGui::NewLine();
|
|
||||||
if (ImGui::Button("Show Advanced options ")) {
|
|
||||||
ShowAdvancedOptions = !ShowAdvancedOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ShowAdvancedOptions)
|
|
||||||
{
|
|
||||||
ImGui::Checkbox("Debug Engine", &DebugEngine);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "../EditorWindow.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Settings : public EditorWindow {
|
|
||||||
public:
|
|
||||||
Settings() : EditorWindow("Settings") {}
|
|
||||||
|
|
||||||
void Draw() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int selectedGfxAPI = 0;
|
|
||||||
int selectedPhysicsEngine = 0;
|
|
||||||
glm::vec3 Gravity = glm::vec3(0.0f, -9.81f, 0.0f);
|
|
||||||
bool ShowAdvancedOptions = false;
|
|
||||||
bool DebugEngine = false;
|
|
||||||
|
|
||||||
const char* PhysicsEngine[2] = {
|
|
||||||
"PhysX",
|
|
||||||
"Jolt Physics"
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* GraphicsAPI[3] = {
|
|
||||||
"OpenGL",
|
|
||||||
"Vulkan",
|
|
||||||
"Metal (Apple)"
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
@ -1,7 +1,6 @@
|
|||||||
#include "../../YoggieEngine/src/EntryPoint.h"
|
|
||||||
#include <stack>
|
|
||||||
#include "EditorLayer.h"
|
#include "EditorLayer.h"
|
||||||
|
#include "EntryPoint.h"
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
using namespace YoggieEngine;
|
using namespace YoggieEngine;
|
||||||
|
|
||||||
@ -9,51 +8,10 @@ class Editor : public Application {
|
|||||||
public:
|
public:
|
||||||
Editor() : Application("Editor") {}
|
Editor() : Application("Editor") {}
|
||||||
|
|
||||||
void Run() override
|
void Run() override {
|
||||||
{
|
PushLayer(new EditorLayer());
|
||||||
|
Application::Run();
|
||||||
|
|
||||||
// Create EditorLayer
|
|
||||||
EditorLayer* firstLayer = new EditorLayer();
|
|
||||||
|
|
||||||
firstLayer->OnStartup();
|
|
||||||
|
|
||||||
|
|
||||||
double previous = glfwGetTime();
|
|
||||||
double lag = 0.0;
|
|
||||||
while (!appWindow->WindowShouldClose()) {
|
|
||||||
PollEvents();
|
|
||||||
double now = glfwGetTime();
|
|
||||||
double elapsed = now - previous;
|
|
||||||
previous = now;
|
|
||||||
lag += elapsed;
|
|
||||||
GuiBegin();
|
|
||||||
firstLayer->OnUpdate();
|
|
||||||
firstLayer->OnUI();
|
|
||||||
GuiEnd();
|
|
||||||
|
|
||||||
SwapBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
firstLayer->OnDestroy();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Layer*> layers = std::vector<Layer*>();
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
YoggieEngine::Application* CreateApplication() {
|
YoggieEngine::Application *CreateApplication() { return new Editor(); }
|
||||||
|
|
||||||
return new Editor();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
6
SandboxApp/CMakeLists.txt
Normal file
6
SandboxApp/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
file(GLOB SOURCE_FILES "src/*.cpp")
|
||||||
|
file(GLOB HEADER_FILES "src/*.h")
|
||||||
|
add_executable(SandboxApp ${SOURCE_FILES} ${HEADER_FILES} )
|
||||||
|
target_link_directories(SandboxApp PRIVATE "../build/YoggieEngine/Debug")
|
||||||
|
target_link_libraries(SandboxApp YoggieEngine)
|
||||||
|
target_include_directories(SandboxApp PRIVATE "../YoggieEngine/src")
|
@ -1,40 +0,0 @@
|
|||||||
project "SandboxApp"
|
|
||||||
kind "ConsoleApp"
|
|
||||||
|
|
||||||
buildmessage "Building SandboxApp ..."
|
|
||||||
|
|
||||||
links{
|
|
||||||
"YoggieEngine"
|
|
||||||
}
|
|
||||||
|
|
||||||
includedirs{
|
|
||||||
"./../YoggieEngine/Include",
|
|
||||||
|
|
||||||
-- I'd prefer if didn't need these..
|
|
||||||
-- We'll figure that out some time later
|
|
||||||
"./../libs/lua/include",
|
|
||||||
"./../libs/spdlog/include",
|
|
||||||
"./../libs/glm",
|
|
||||||
"./../libs/GorillaAudio/include",
|
|
||||||
|
|
||||||
"./../libs/assimp/include",
|
|
||||||
"./../libs/glad/include",
|
|
||||||
"./../libs/glfw/include",
|
|
||||||
"./../libs/tinygltf",
|
|
||||||
"./../libs/glew/include",
|
|
||||||
"./../libs/glm",
|
|
||||||
"./../libs/ImGui",
|
|
||||||
|
|
||||||
"../libs/entt/src",
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
'./../YoggieEngine/build/Debug'
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"./src/*.h",
|
|
||||||
"./src/*.cpp"
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "YoggieEngine.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "../../YoggieEngine/src/BarinkEngine.h"
|
|
||||||
#include "../../YoggieEngine/src/Graphics/Memory/Framebuffer.h"
|
|
||||||
|
|
||||||
void CameraTool();
|
void CameraTool();
|
||||||
void ScriptingTool(char *code);
|
void ScriptingTool(char *code);
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
#include <imgui.h>
|
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <entt/entt.hpp>
|
#include <entt/entt.hpp>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
#include "../../YoggieEngine/src/BarinkEngine.h"
|
#include "YoggieEngine.h"
|
||||||
#include "../../YoggieEngine/src/Scene/Components.h"
|
|
||||||
#include "../../YoggieEngine/src/Scene/Scene.h"
|
|
||||||
#include "../../YoggieEngine/src/Scene/Entity.h"
|
|
||||||
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
|
|
||||||
#include "../../YoggieEngine/src/PerfCounter.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define globals
|
* Define globals
|
||||||
@ -31,14 +25,13 @@ void Start() {
|
|||||||
object = importer.Import("build/Debug/Models/Cube.obj");
|
object = importer.Import("build/Debug/Models/Cube.obj");
|
||||||
renderable = object->renderable;
|
renderable = object->renderable;
|
||||||
|
|
||||||
|
|
||||||
// Add Entities to the scene
|
// Add Entities to the scene
|
||||||
cube = scene.AddEntity("cube");
|
cube = scene.AddEntity("cube");
|
||||||
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
auto &render3DComponent =
|
||||||
|
cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||||
render3DComponent.mesh = *renderable->mesh;
|
render3DComponent.mesh = *renderable->mesh;
|
||||||
cube.GetComponent<BarinkEngine::TransformComponent>()
|
cube.GetComponent<BarinkEngine::TransformComponent>().transform =
|
||||||
.transform = glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f,1.0f,0.0f));
|
glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f, 1.0f, 0.0f));
|
||||||
|
|
||||||
|
|
||||||
// Create a second cube
|
// Create a second cube
|
||||||
|
|
||||||
@ -47,32 +40,28 @@ void Start() {
|
|||||||
cube2Render.mesh = *renderable->mesh;
|
cube2Render.mesh = *renderable->mesh;
|
||||||
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
|
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
auto &cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
|
auto &cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
|
||||||
cube2Trans.transform = glm::translate( glm::mat4(1.0f), glm::vec3(1.0f,0.0f, 5.0f));
|
cube2Trans.transform =
|
||||||
|
glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0.0f, 5.0f));
|
||||||
|
|
||||||
// Create a light
|
// Create a light
|
||||||
auto AmbientLight = scene.AddEntity("AmbientLight");
|
auto AmbientLight = scene.AddEntity("AmbientLight");
|
||||||
AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
||||||
|
|
||||||
renderer.Prepare(scene);
|
renderer.Prepare(scene);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs every frame
|
* Runs every frame
|
||||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||||
*/
|
*/
|
||||||
void ImmediateGraphicsDraw()
|
void ImmediateGraphicsDraw() {
|
||||||
{
|
|
||||||
// Show internal BarinkEngine stats
|
// Show internal BarinkEngine stats
|
||||||
EngineInstrumentation::ShowStats();
|
EngineInstrumentation::ShowStats();
|
||||||
|
|
||||||
ImGui::Begin("Scene view");
|
ImGui::Begin("Scene view");
|
||||||
auto group = scene.getReg().view<BarinkEngine::IdentifierComponent>();
|
auto group = scene.getReg().view<BarinkEngine::IdentifierComponent>();
|
||||||
group.each([](auto entity, BarinkEngine::IdentifierComponent &identifier) {
|
group.each([](auto entity, BarinkEngine::IdentifierComponent &identifier) {
|
||||||
|
|
||||||
ImGui::Text("%s", identifier.name.c_str());
|
ImGui::Text("%s", identifier.name.c_str());
|
||||||
|
|
||||||
});
|
});
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
@ -80,7 +69,6 @@ void ImmediateGraphicsDraw()
|
|||||||
|
|
||||||
ImGui::Begin("Settings");
|
ImGui::Begin("Settings");
|
||||||
|
|
||||||
|
|
||||||
auto &a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
auto &a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
||||||
|
|
||||||
auto &b = cube.GetComponent<BarinkEngine::TransformComponent>();
|
auto &b = cube.GetComponent<BarinkEngine::TransformComponent>();
|
||||||
@ -94,30 +82,21 @@ void ImmediateGraphicsDraw()
|
|||||||
ImGui::Text("Lighting");
|
ImGui::Text("Lighting");
|
||||||
ImGui::SliderFloat("Intensity", &light.Strength, 0.0f, 1.0f);
|
ImGui::SliderFloat("Intensity", &light.Strength, 0.0f, 1.0f);
|
||||||
ImGui::SliderFloat3("l-Color", &light.Color[0], 0.0f, 1.0f);
|
ImGui::SliderFloat3("l-Color", &light.Color[0], 0.0f, 1.0f);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs every frame
|
* Runs every frame
|
||||||
* - Meant for game logic ( non-physics related)
|
* - Meant for game logic ( non-physics related)
|
||||||
*/
|
*/
|
||||||
void Update()
|
void Update() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Render()
|
void Render() { renderer.Render(scene); }
|
||||||
{
|
|
||||||
renderer.Render(scene);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs at the end of the program
|
* Runs at the end of the program
|
||||||
* - Meant for cleanup
|
* - Meant for cleanup
|
||||||
*/
|
*/
|
||||||
void Stop()
|
void Stop() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../YoggieEngine/src/BarinkEngine.h"
|
#include "YoggieEngine.h"
|
||||||
|
|
||||||
// void PrintSceneTree(Node& node, int depth);
|
// void PrintSceneTree(Node& node, int depth);
|
||||||
|
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
|
|
||||||
TEST(HelloTDD, MyFirstTest) {
|
|
||||||
EXPECT_EQ(1, 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(TRANSFORM_COMPONENT_TESTS , CAN_EXTRACT_TRANSLATION_FROM_TRANSFORM_MATRIX) {
|
|
||||||
|
|
||||||
auto component = YoggieEngine::TransformComponent{};
|
|
||||||
|
|
||||||
component.Position = glm::vec3(1.0f, 2.0f, 3.0f);
|
|
||||||
auto transformationMatrix = component.GetTransform();
|
|
||||||
|
|
||||||
auto newComponent = YoggieEngine::TransformComponent{};
|
|
||||||
|
|
||||||
newComponent.Decompose(transformationMatrix);
|
|
||||||
|
|
||||||
EXPECT_EQ(newComponent.Position.x, component.Position.x);
|
|
||||||
EXPECT_EQ(newComponent.Position.y, component.Position.y);
|
|
||||||
EXPECT_EQ(newComponent.Position.z, component.Position.z);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
|
||||||
|
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
|
||||||
return RUN_ALL_TESTS();
|
|
||||||
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
project "EngineTests"
|
|
||||||
kind "ConsoleApp"
|
|
||||||
language "C++"
|
|
||||||
targetdir "bin/%{cfg.buildcfg}"
|
|
||||||
|
|
||||||
files{"**.h", "**.cpp"}
|
|
||||||
|
|
||||||
includedirs{
|
|
||||||
"../YoggieEngine/src",
|
|
||||||
incfolder["lua"],
|
|
||||||
incfolder["spdlog"],
|
|
||||||
incfolder["glm"],
|
|
||||||
incfolder["glad"],
|
|
||||||
incfolder["glfw"],
|
|
||||||
incfolder["imgui"],
|
|
||||||
incfolder["imguizmo"],
|
|
||||||
incfolder["entt"],
|
|
||||||
"../libs/physx/physx/include",
|
|
||||||
"../libs/physx/pxshared/include",
|
|
||||||
incfolder["GoogleTest"]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
staticlib["yoggie"],
|
|
||||||
staticlib["GoogleTest"]
|
|
||||||
}
|
|
||||||
|
|
||||||
links{
|
|
||||||
"YoggieEngine",
|
|
||||||
"gtest"
|
|
||||||
}
|
|
22
YoggieEngine/CMakeLists.txt
Normal file
22
YoggieEngine/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
file(GLOB SOURCE_FILES src/*.cpp)
|
||||||
|
add_library(YoggieEngine ${SOURCE_FILES} )
|
||||||
|
#target_precompile_headers(YoggieEngine PUBLIC src/YoggieEngine.h )
|
||||||
|
|
||||||
|
target_link_directories(YoggieEngine PUBLIC
|
||||||
|
"../libs/physx/physx/bin/win.x86_64.vc142.md/debug"
|
||||||
|
)
|
||||||
|
target_link_libraries(YoggieEngine
|
||||||
|
thirdparty_tools
|
||||||
|
PhysX_64
|
||||||
|
PhysXCooking_64
|
||||||
|
PhysXCommon_64
|
||||||
|
PhysXFoundation_64
|
||||||
|
PhysXPvdSDK_static_64
|
||||||
|
PhysXExtensions_static_64
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(YoggieEngine PUBLIC
|
||||||
|
"../libs/physx/pxshared/include"
|
||||||
|
"../libs/physx/physx/include"
|
||||||
|
)
|
||||||
|
|
@ -1,87 +0,0 @@
|
|||||||
project "YoggieEngine"
|
|
||||||
kind "StaticLib"
|
|
||||||
|
|
||||||
pchheader "YoggieEngine.h"
|
|
||||||
pchsource "src/YoggieEngine.cpp"
|
|
||||||
|
|
||||||
|
|
||||||
buildmessage "Building Yoggie Engine"
|
|
||||||
disablewarnings{
|
|
||||||
"4099" -- Ignore the missing debug signals for GLFW warning
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
filter "system:Windows"
|
|
||||||
defines{
|
|
||||||
"GLFW"
|
|
||||||
}
|
|
||||||
|
|
||||||
includedirs {
|
|
||||||
"./src",
|
|
||||||
"../libs/spdlog/include",
|
|
||||||
"../libs/glm",
|
|
||||||
|
|
||||||
"../libs/glfw/include",
|
|
||||||
"../libs/glew/include",
|
|
||||||
"../libs/glad/include",
|
|
||||||
|
|
||||||
|
|
||||||
"../libs/assimp/include",
|
|
||||||
"../libs/entt/src",
|
|
||||||
|
|
||||||
"../libs/physx/pxshared/include",
|
|
||||||
"../libs/physx/physx/include",
|
|
||||||
|
|
||||||
"../libs/lua/include",
|
|
||||||
|
|
||||||
"../libs/GorillaAudio/include",
|
|
||||||
"../libs/steam-audio/include",
|
|
||||||
|
|
||||||
"../libs/ImGui",
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
links {
|
|
||||||
-- This needs to fall under the filter as the names can differ on different platforms
|
|
||||||
"phonon",
|
|
||||||
"lua54",
|
|
||||||
"spdlog",
|
|
||||||
"assimp-vc143-mtd",
|
|
||||||
"glfw3",
|
|
||||||
"ImGui",
|
|
||||||
|
|
||||||
"PhysX_64",
|
|
||||||
"PhysXCooking_64",
|
|
||||||
"PhysXCommon_64",
|
|
||||||
"PhysXFoundation_64",
|
|
||||||
"PhysXPvdSDK_static_64",
|
|
||||||
"PhysXExtensions_static_64"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
"../libs/steam-audio/lib/windows-x64",
|
|
||||||
"../libs/lua",
|
|
||||||
"../libs/spdlog/build/Release",
|
|
||||||
"../libs/assimp/lib/Debug",
|
|
||||||
"../libs/glfw/build/src/Debug",
|
|
||||||
"../libs/physx/physx/bin/win.x86_64.vc142.md/debug",
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
|
|
||||||
"src/**.cpp",
|
|
||||||
"src/**.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
prebuildcommands
|
|
||||||
{
|
|
||||||
ok,err = os.copyfile("YoggieEngine/src/Graphics/shaders/*" ,"SandboxApp/build/Debug/")
|
|
||||||
}
|
|
||||||
|
|
||||||
postbuildcommands
|
|
||||||
{
|
|
||||||
ok,err = os.copyfile("YoggieEngine/build/Debug/intermediates/YoggieEngine.pch", "YoggieEngine/build/Debug/YoggieEngine.pch")
|
|
||||||
}
|
|
||||||
|
|
@ -50,12 +50,57 @@ namespace YoggieEngine {
|
|||||||
//ImGuizmo::SetOrthographic(true);
|
//ImGuizmo::SetOrthographic(true);
|
||||||
|
|
||||||
|
|
||||||
init_inputSystem(appWindow);
|
//init_inputSystem(appWindow);
|
||||||
|
glfwSetWindowUserPointer((GLFWwindow*)this->appWindow->GetHandle(), this);
|
||||||
|
glfwSetKeyCallback((GLFWwindow*)this->appWindow->GetHandle(), HandleKey);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Application::HandleKey(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||||
|
auto app = (Application*)glfwGetWindowUserPointer(window);
|
||||||
|
for (auto i = app->AppLayerstack.begin(); i < app->AppLayerstack.end(); i++) {
|
||||||
|
if ((*i)->OnKey(key, action)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Application::Run() {
|
void Application::Run() {
|
||||||
|
|
||||||
|
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnStartup();
|
||||||
|
}
|
||||||
|
|
||||||
|
double previous = glfwGetTime();
|
||||||
|
double lag = 0.0;
|
||||||
|
|
||||||
|
while (!appWindow->WindowShouldClose()) {
|
||||||
|
PollEvents();
|
||||||
|
double now = glfwGetTime();
|
||||||
|
double elapsed = now - previous;
|
||||||
|
previous = now;
|
||||||
|
lag += elapsed;
|
||||||
|
|
||||||
|
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiBegin();
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnUI();
|
||||||
|
}
|
||||||
|
GuiEnd();
|
||||||
|
|
||||||
|
SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,14 +19,19 @@ namespace YoggieEngine {
|
|||||||
void GuiEnd();
|
void GuiEnd();
|
||||||
|
|
||||||
void PushLayer(Layer* layer);
|
void PushLayer(Layer* layer);
|
||||||
|
static Application& Get() { return *Application::instance; }
|
||||||
|
static void HandleKey(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
|
static void HandleMouseButton(GLFWwindow* window, int button, int action, int mods);
|
||||||
|
static void HandleScroll(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
protected:
|
protected:
|
||||||
std::string m_AppName;
|
std::string m_AppName;
|
||||||
NativeWindow* appWindow;
|
NativeWindow* appWindow;
|
||||||
|
|
||||||
LayerStack AppLayerstack;
|
LayerStack AppLayerstack;
|
||||||
|
Layer* guiLayer;
|
||||||
|
static Application* instance ;
|
||||||
|
|
||||||
|
friend class ImGuiLayer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
22
YoggieEngine/src/Assets/Asset.h
Normal file
22
YoggieEngine/src/Assets/Asset.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "uuid.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef uuid::v4::UUID AssetHandle;
|
||||||
|
|
||||||
|
|
||||||
|
enum class AssetType {
|
||||||
|
Unknown = -1,
|
||||||
|
Mesh,
|
||||||
|
Texture,
|
||||||
|
Material,
|
||||||
|
Shader
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Asset {
|
||||||
|
AssetHandle Handle;
|
||||||
|
|
||||||
|
template<class T >
|
||||||
|
static AssetType GetType(T t) { return t.GetType(); }
|
||||||
|
virtual AssetType GetType() { return AssetType::Unknown; }
|
||||||
|
};
|
143
YoggieEngine/src/Assets/AssetImporter.cpp
Normal file
143
YoggieEngine/src/Assets/AssetImporter.cpp
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
#include <YoggieEngine.h>
|
||||||
|
#include "AssetImporter.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
#include <assimp/postprocess.h>
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
|
||||||
|
namespace YoggieEngine {
|
||||||
|
|
||||||
|
void ProcessVertices(aiMesh* mesh, std::vector<YoggieEngine::Vertex>& out_vertices) {
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||||
|
YoggieEngine::Vertex v{};
|
||||||
|
|
||||||
|
glm::vec3 vector{};
|
||||||
|
vector.x = mesh->mVertices[i].x;
|
||||||
|
vector.y = mesh->mVertices[i].y;
|
||||||
|
vector.z = mesh->mVertices[i].z;
|
||||||
|
|
||||||
|
v.vertices = vector;
|
||||||
|
|
||||||
|
if (mesh->mTextureCoords[0]) {
|
||||||
|
glm::vec2 texCoord{};
|
||||||
|
|
||||||
|
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||||
|
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||||
|
|
||||||
|
v.uv = texCoord;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
out_vertices.push_back(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||||
|
aiFace face = mesh->mFaces[i];
|
||||||
|
if (face.mNumIndices < 3)
|
||||||
|
continue;
|
||||||
|
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||||
|
out_indices.push_back(face.mIndices[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
YoggieEngine::Mesh processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||||
|
std::vector<unsigned int> indices;
|
||||||
|
std::vector<YoggieEngine::Vertex> vertices;
|
||||||
|
|
||||||
|
ProcessVertices(mesh, vertices);
|
||||||
|
ProcessIndices(mesh, indices);
|
||||||
|
|
||||||
|
YoggieEngine::Mesh result;
|
||||||
|
result.vertices = vertices;
|
||||||
|
result.elements = indices;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<YoggieEngine::Mesh> processNode(aiNode* node, const aiScene* scene) {
|
||||||
|
|
||||||
|
std::vector<YoggieEngine::Mesh> meshes = std::vector<YoggieEngine::Mesh>();
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||||
|
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||||
|
meshes.push_back(processMesh(mesh, scene));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
||||||
|
auto m2 = processNode(node->mChildren[i], scene);
|
||||||
|
|
||||||
|
for (auto m : m2) {
|
||||||
|
meshes.push_back(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshes;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadModelFile(std::filesystem::path path) {
|
||||||
|
Assimp::Importer importer;
|
||||||
|
const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
aiNode* currentNode = scene->mRootNode;
|
||||||
|
auto meshes = processNode(currentNode, scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsSupportedImageFormat(const std::string& extension) {
|
||||||
|
static std::vector<std::string> supported_image_extensions = { "jpeg", "jpg", "png","bmp","hdr","psd","tga","gif","pic","psd","pgm","ppm" };
|
||||||
|
|
||||||
|
for (auto support_extension : supported_image_extensions) {
|
||||||
|
if (extension == support_extension)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Asset AssetImporter::ImportAsset(AssetMetadata& metadata) {
|
||||||
|
|
||||||
|
static Asset emptyAsset;
|
||||||
|
|
||||||
|
|
||||||
|
// Check file extension so we can choose our loader
|
||||||
|
if (metadata.filepath.has_extension() == true)
|
||||||
|
{
|
||||||
|
spdlog::error("Asset file has no extension!");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto extension = metadata.filepath.extension().string();
|
||||||
|
|
||||||
|
// Handle as Model file
|
||||||
|
bool IsSupportedModelFile = importer.IsExtensionSupported(extension);
|
||||||
|
if (IsSupportedModelFile) {
|
||||||
|
LoadModelFile(metadata.filepath);
|
||||||
|
return emptyAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Handle as Texture
|
||||||
|
if (IsSupportedImageFormat(extension))
|
||||||
|
{
|
||||||
|
Texture texture;
|
||||||
|
texture.Load(metadata.filepath.string());
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle as shader
|
||||||
|
if (extension == "glsl" || extension == "vert" || extension == "frag") {
|
||||||
|
//Shader shader;
|
||||||
|
//shader.
|
||||||
|
return emptyAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return emptyAsset;
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
12
YoggieEngine/src/Assets/AssetImporter.h
Normal file
12
YoggieEngine/src/Assets/AssetImporter.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "AssetMetadata.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
namespace YoggieEngine{
|
||||||
|
class AssetImporter {
|
||||||
|
public:
|
||||||
|
static Asset ImportAsset(AssetMetadata& metadata);
|
||||||
|
private:
|
||||||
|
static Assimp::Importer importer;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
16
YoggieEngine/src/Assets/AssetManager.h
Normal file
16
YoggieEngine/src/Assets/AssetManager.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <map>
|
||||||
|
#include "AssetMetaData.h"
|
||||||
|
|
||||||
|
typedef std::map<AssetHandle, AssetMetadata> AssetRegistry;
|
||||||
|
|
||||||
|
class AssetManager {
|
||||||
|
public:
|
||||||
|
virtual Asset& GetAsset(AssetHandle handle) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
AssetRegistry Assets;
|
||||||
|
std::map<AssetHandle, Asset> LoadedAssets;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
41
YoggieEngine/src/Assets/AssetManagerEditor.cpp
Normal file
41
YoggieEngine/src/Assets/AssetManagerEditor.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "YoggieEngine.h"
|
||||||
|
#include "AssetManagerEditor.h"
|
||||||
|
#include "AssetImporter.h"
|
||||||
|
using namespace YoggieEngine;
|
||||||
|
|
||||||
|
Asset& AssetManagerEditor::GetAsset(AssetHandle handle)
|
||||||
|
{
|
||||||
|
static Asset EmptyAsset{};
|
||||||
|
|
||||||
|
// 1. Check if handle is valid
|
||||||
|
if (IsAssetHandleValid(handle) == false)
|
||||||
|
return EmptyAsset;
|
||||||
|
|
||||||
|
// 2. check if asset needs loading
|
||||||
|
Asset asset;
|
||||||
|
if (IsAssetLoaded(handle)) {
|
||||||
|
asset = LoadedAssets.at(handle);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Load asset
|
||||||
|
// Get MetaData
|
||||||
|
//auto& metadata = Assets[handle];
|
||||||
|
|
||||||
|
// Load Asset
|
||||||
|
//asset = AssetImporter::ImportAsset(metadata);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. return asset.
|
||||||
|
return asset;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManagerEditor::IsAssetHandleValid(AssetHandle handle)
|
||||||
|
{
|
||||||
|
return Assets.find(handle) != Assets.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManagerEditor::IsAssetLoaded(AssetHandle handle ) {
|
||||||
|
return LoadedAssets.find(handle) != LoadedAssets.end();
|
||||||
|
}
|
11
YoggieEngine/src/Assets/AssetManagerEditor.h
Normal file
11
YoggieEngine/src/Assets/AssetManagerEditor.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "AssetManager.h"
|
||||||
|
|
||||||
|
class AssetManagerEditor : public AssetManager {
|
||||||
|
public:
|
||||||
|
Asset& GetAsset(AssetHandle handle) override;
|
||||||
|
private:
|
||||||
|
bool IsAssetHandleValid(AssetHandle handle);
|
||||||
|
bool IsAssetLoaded(AssetHandle handle);
|
||||||
|
|
||||||
|
};
|
7
YoggieEngine/src/Assets/AssetMetadata.h
Normal file
7
YoggieEngine/src/Assets/AssetMetadata.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <filesystem>
|
||||||
|
#include "Asset.h"
|
||||||
|
struct AssetMetadata{
|
||||||
|
AssetHandle handle;
|
||||||
|
std::filesystem::path filepath;
|
||||||
|
};
|
@ -16,23 +16,33 @@ namespace uuid::v4
|
|||||||
class UUID
|
class UUID
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Factory method for creating UUID object.
|
UUID() {}
|
||||||
static UUID New()
|
// I need a better UUID class that will work as a key in std::map
|
||||||
|
// because this won't properly work
|
||||||
|
|
||||||
|
bool operator() (const UUID& lhs, const UUID& rhs) const {
|
||||||
|
return 1==1;
|
||||||
|
}
|
||||||
|
bool operator< (const UUID& rhs)const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// method for creating UUID object.
|
||||||
|
void generate ()
|
||||||
{
|
{
|
||||||
UUID uuid;
|
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::mt19937 engine{ rd() };
|
std::mt19937 engine{ rd() };
|
||||||
std::uniform_int_distribution<int> dist{ 0, 256 }; //Limits of the interval
|
std::uniform_int_distribution<int> dist{ 0, 256 }; //Limits of the interval
|
||||||
|
|
||||||
for (int index = 0; index < 16; ++index)
|
for (int index = 0; index < 16; ++index)
|
||||||
{
|
{
|
||||||
uuid._data[index] = (unsigned char)dist(engine);
|
_data[index] = (unsigned char)dist(engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid._data[6] = ((uuid._data[6] & 0x0f) | 0x40); // Version 4
|
_data[6] = ((_data[6] & 0x0f) | 0x40); // Version 4
|
||||||
uuid._data[8] = ((uuid._data[8] & 0x3f) | 0x80); // Variant is 10
|
_data[8] = ((_data[8] & 0x3f) | 0x80); // Variant is 10
|
||||||
|
|
||||||
|
|
||||||
return uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns UUID as formatted string
|
// Returns UUID as formatted string
|
||||||
@ -54,7 +64,6 @@ namespace uuid::v4
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UUID() {}
|
|
||||||
|
|
||||||
unsigned char _data[16] = { 0 };
|
unsigned char _data[16] = { 0 };
|
||||||
};
|
};
|
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace YoggieEngine {
|
|
||||||
|
|
||||||
struct Event
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string name;
|
|
||||||
int argc;
|
|
||||||
void** argv;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include "EventEmitter.h"
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
|
||||||
|
|
||||||
void EventEmitter::Subscribe(EventListener& subscriber)
|
|
||||||
{
|
|
||||||
subscribers.push_back(&subscriber);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventEmitter::Unsubscribe(EventListener& subscriber)
|
|
||||||
{
|
|
||||||
subscribers.remove(&subscriber);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventEmitter::EmitEvent(Event& incident)
|
|
||||||
{
|
|
||||||
// Notify all subscribers an event has taken place
|
|
||||||
for (auto it = subscribers.begin(); it != subscribers.end(); ++it)
|
|
||||||
{
|
|
||||||
(*it)->ReceiveEvent(incident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EventEmitter::EventEmitter() {
|
|
||||||
subscribers = std::list<EventListener*>{};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace YoggieEngine{
|
|
||||||
class EventEmitter {
|
|
||||||
public:
|
|
||||||
void Subscribe(EventListener& subscriber);
|
|
||||||
void Unsubscribe(EventListener& subscriber);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::list<EventListener*> subscribers;
|
|
||||||
void EmitEvent(Event& incident);
|
|
||||||
|
|
||||||
EventEmitter();
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Event.h"
|
|
||||||
namespace YoggieEngine {
|
|
||||||
class EventListener {
|
|
||||||
public:
|
|
||||||
virtual void ReceiveEvent(Event& incident) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
42
YoggieEngine/src/Graphics/Camera.h
Normal file
42
YoggieEngine/src/Graphics/Camera.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
|
namespace YoggieEngine {
|
||||||
|
class Camera {
|
||||||
|
public:
|
||||||
|
Camera() {
|
||||||
|
projection = glm::perspective(glm::radians(90.0f), 800.0f / 600.0f, 0.001f, 1000.0f);
|
||||||
|
//projection[3][1] *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 getTransform() const {
|
||||||
|
|
||||||
|
auto transform = glm::translate(glm::mat4(1.0f), Position)
|
||||||
|
* glm::toMat4(glm::quat(Rotation))
|
||||||
|
* glm::scale(glm::mat4(1.0f), glm::vec3(1.0f));
|
||||||
|
|
||||||
|
return glm::inverse(transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4& getProjection(float width, float height) {
|
||||||
|
|
||||||
|
//projection[3][1] *= -1;
|
||||||
|
|
||||||
|
return projection;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Position = glm::vec3(0.0f);
|
||||||
|
glm::vec3 Rotation = glm::vec3(0.0f);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
glm::mat4 view;
|
||||||
|
glm::mat4 projection;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -1,11 +1,42 @@
|
|||||||
#include <YoggieEngine.h>
|
#include <YoggieEngine.h>
|
||||||
#include "OpenglAPI.h"
|
#include "OpenglAPI.h"
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
|
|
||||||
|
GLenum glCheckError_(const char* file, int line) {
|
||||||
|
GLenum errorCode;
|
||||||
|
while ((errorCode = glGetError()) != GL_NO_ERROR) {
|
||||||
|
std::string error;
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case GL_INVALID_ENUM: error = "INVALID_ENUM"; break;
|
||||||
|
case GL_INVALID_VALUE: error = "INVALID_VALUE"; break;
|
||||||
|
case GL_INVALID_OPERATION: error = "INVALID_OPERATION"; break;
|
||||||
|
case GL_STACK_OVERFLOW: error = "STACK_OVERFLOW"; break;
|
||||||
|
case GL_STACK_UNDERFLOW: error = "STACK_UNDERFLOW"; break;
|
||||||
|
case GL_OUT_OF_MEMORY: error = "OUT_OF_MEMORY"; break;
|
||||||
|
case GL_INVALID_FRAMEBUFFER_OPERATION: error = "INVALID_FRAMEBUFFER_OPERATION"; break;
|
||||||
|
};
|
||||||
|
spdlog::error("{0} | {1} ({2})", error, file, line);
|
||||||
|
}
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define glCheckError() glCheckError_(__FILE__, __LINE__)
|
||||||
|
#else
|
||||||
|
#define glCheckError()
|
||||||
|
#endif
|
||||||
|
|
||||||
void OpenGLApi::DrawTriangles(Render3DComponent rc) {
|
void OpenGLApi::DrawTriangles(Render3DComponent rc) {
|
||||||
|
|
||||||
glBindVertexArray(rc.VAO);
|
glBindVertexArray(rc.VAO);
|
||||||
|
glCheckError();
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rc.IBO);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rc.IBO);
|
||||||
|
glCheckError();
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int> (rc.mesh.elements.size()), GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int> (rc.mesh.elements.size()), GL_UNSIGNED_INT, 0);
|
||||||
|
glCheckError();
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,10 +45,12 @@ namespace YoggieEngine {
|
|||||||
void OpenGLApi::DrawCubeMap(unsigned int VertexAttributeObject, CubeMap CubeTexture) {
|
void OpenGLApi::DrawCubeMap(unsigned int VertexAttributeObject, CubeMap CubeTexture) {
|
||||||
|
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, CubeTexture.getID());
|
glBindTexture(GL_TEXTURE_CUBE_MAP, CubeTexture.getID());
|
||||||
|
//glCheckError(); // INVALID ENUM FOR SOME REASON
|
||||||
glBindVertexArray(VertexAttributeObject);
|
glBindVertexArray(VertexAttributeObject);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
//glCheckError();
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace YoggieEngine {
|
|
||||||
class Camera {
|
|
||||||
public:
|
|
||||||
Camera() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::mat4 view;
|
|
||||||
glm::mat4 projection;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../Graphics/Memory/Buffer.h"
|
#include "../Graphics/Buffer.h"
|
||||||
#include "../Graphics/Memory/VertexArray.h"
|
#include "../Graphics/VertexArray.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace YoggieEngine {
|
|
||||||
|
|
||||||
struct Renderable {
|
|
||||||
Mesh* mesh;
|
|
||||||
Material* material;
|
|
||||||
Texture* texture;
|
|
||||||
};
|
|
||||||
}
|
|
@ -2,8 +2,13 @@
|
|||||||
|
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "../Scene/Components.h"
|
#include "../Scene/Components.h"
|
||||||
#include "../Graphics/Memory/Buffer.h"
|
#include "../Graphics/Buffer.h"
|
||||||
#include "../Graphics/Memory/VertexArray.h"
|
#include "../Graphics/VertexArray.h"
|
||||||
|
#include "Framebuffer.h"
|
||||||
|
#include "../Scene/Components.h"
|
||||||
|
#include"../Scene/Scene.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
#include "OpenglAPI.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
unsigned int quadVAO = 0;
|
unsigned int quadVAO = 0;
|
||||||
@ -66,7 +71,7 @@ float skyboxVertices[]{
|
|||||||
|
|
||||||
|
|
||||||
Renderer::Renderer() :
|
Renderer::Renderer() :
|
||||||
m_framebuffer(960, 540),
|
m_framebuffer(800, 600),
|
||||||
gBufferShader("build/Debug/Shaders/deferred/geometry.vert", "build/Debug/Shaders/deferred/geometry.frag"),
|
gBufferShader("build/Debug/Shaders/deferred/geometry.vert", "build/Debug/Shaders/deferred/geometry.frag"),
|
||||||
lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"),
|
lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"),
|
||||||
SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"),
|
SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"),
|
||||||
@ -74,8 +79,8 @@ Renderer::Renderer() :
|
|||||||
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag"),
|
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag"),
|
||||||
postProcessingShader("build/Debug/Shaders/forward/postprocessing.vert", "build/Debug/Shaders/forward/postprocessing.frag")
|
postProcessingShader("build/Debug/Shaders/forward/postprocessing.vert", "build/Debug/Shaders/forward/postprocessing.frag")
|
||||||
{
|
{
|
||||||
width = 960;
|
width = 800;
|
||||||
height = 540;
|
height = 600;
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
CreateGBuffer();
|
CreateGBuffer();
|
||||||
|
|
||||||
@ -89,6 +94,7 @@ Renderer::Renderer() :
|
|||||||
};
|
};
|
||||||
|
|
||||||
skybox = CubeMap(faces);
|
skybox = CubeMap(faces);
|
||||||
|
grassTexture.Load("build/Debug/Texture/grass.png");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +148,180 @@ void Renderer::CreateGBuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Renderer::Render(Scene& scene , Camera MainCamera){
|
||||||
|
int oldviewport[4];
|
||||||
|
glGetIntegerv(GL_VIEWPORT, oldviewport);
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Render skybox if the scene has one
|
||||||
|
|
||||||
|
SkyboxShader.Use();
|
||||||
|
SkyboxShader.setUniformMat4("projection", MainCamera.getProjection(width, height));
|
||||||
|
SkyboxShader.setUniformMat4("view", glm::inverse(glm::mat4(glm::mat3(MainCamera.getTransform()))));
|
||||||
|
|
||||||
|
if (!skyboxVAO) {
|
||||||
|
unsigned int VBO;
|
||||||
|
glGenVertexArrays(1, &skyboxVAO);
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindVertexArray(skyboxVAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenGLApi::DrawCubeMap(skyboxVAO, skybox);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
auto renderables = scene.getReg().view<TransformComponent, Render3DComponent>();
|
||||||
|
gBufferShader.Use();
|
||||||
|
for (auto renderable : renderables) {
|
||||||
|
auto entity = Entity(renderable, &scene);
|
||||||
|
auto& renderComponent = entity.GetComponent<Render3DComponent>();
|
||||||
|
auto& transform = entity.GetComponent<TransformComponent>();
|
||||||
|
|
||||||
|
// Geometry pass
|
||||||
|
gBufferShader.setUniformVec3("Color", renderComponent.color);
|
||||||
|
gBufferShader.setUniformMat4("Model", transform.GetTransform());
|
||||||
|
gBufferShader.setUniformMat4("View", glm::inverse(MainCamera.getTransform()));
|
||||||
|
gBufferShader.setUniformMat4("Projection", MainCamera.getProjection(width, height));
|
||||||
|
OpenGLApi::DrawTriangles(renderComponent);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Light pass
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||||
|
lightingPassShader.Use();
|
||||||
|
lightingPassShader.setUniformInt("gPosition", 0);
|
||||||
|
lightingPassShader.setUniformInt("gNormal", 1);
|
||||||
|
lightingPassShader.setUniformInt("gColorSpec", 2);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gPosition);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gNormal);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE2);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gColorSpec);
|
||||||
|
|
||||||
|
auto lights = scene.getReg().view<LightComponent, TransformComponent>();
|
||||||
|
unsigned int lightnr = 0;
|
||||||
|
for (auto light : lights) {
|
||||||
|
auto lightComponent = Entity(light, &scene).GetComponent<LightComponent>();
|
||||||
|
auto transformComponent = Entity(light, &scene).GetComponent<TransformComponent>();
|
||||||
|
|
||||||
|
auto name = "lights[" + std::to_string(lightnr) + "]";
|
||||||
|
lightingPassShader.setUniformVec3(name + ".Position", transformComponent.Position);
|
||||||
|
lightingPassShader.setUniformVec3(name + ".Color", lightComponent.Color);
|
||||||
|
|
||||||
|
const float linear = 0.7f;
|
||||||
|
const float quadratic = 1.8f;
|
||||||
|
lightingPassShader.setUniformFloat(name + ".Linear", linear);
|
||||||
|
lightingPassShader.setUniformFloat(name + ".Quadratic", quadratic);
|
||||||
|
|
||||||
|
lightnr++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quadVAO == 0)
|
||||||
|
{
|
||||||
|
float quadVertices[] = {
|
||||||
|
-1.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
1.0f, 1.0f, 0.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
};
|
||||||
|
unsigned int quadVBO;
|
||||||
|
// setup plane VAO ;
|
||||||
|
glGenVertexArrays(1, &quadVAO);
|
||||||
|
glGenBuffers(1, &quadVBO);
|
||||||
|
glBindVertexArray(quadVAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindVertexArray(quadVAO);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
|
||||||
|
// Copy GBuffer
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
||||||
|
glBindFramebuffer(GL_DRAW_BUFFER, m_framebuffer.GetId());
|
||||||
|
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
||||||
|
|
||||||
|
|
||||||
|
if (transparentVAO == 0) {
|
||||||
|
unsigned int transparentVBO;
|
||||||
|
float transparentVertices[] = {
|
||||||
|
// positions // texture Coords
|
||||||
|
0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
|
0.0f, -0.5f, 0.0f, 0.0f, 0.0f,
|
||||||
|
1.0f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
|
0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
|
1.0f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
|
1.0f, 0.5f, 0.0f, 1.0f, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &transparentVAO);
|
||||||
|
glGenBuffers(1, &transparentVBO);
|
||||||
|
glBindVertexArray(transparentVAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, transparentVBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(transparentVertices), transparentVertices, GL_STATIC_DRAW);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
BlendingShader.Use();
|
||||||
|
glBindVertexArray(transparentVAO);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, grassTexture.GetID());
|
||||||
|
|
||||||
|
BlendingShader.setUniformMat4("V", glm::inverse(MainCamera.getTransform()));
|
||||||
|
BlendingShader.setUniformMat4("P", MainCamera.getProjection(width, height));
|
||||||
|
for (unsigned int i = 0; i < vegetation.size(); i++) {
|
||||||
|
|
||||||
|
auto translation = glm::translate(glm::mat4(1.0f), vegetation[i]);
|
||||||
|
BlendingShader.setUniformMat4("M", translation);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
glViewport(oldviewport[0], oldviewport[1], oldviewport[2], oldviewport[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Renderer::~Renderer(){}
|
Renderer::~Renderer(){}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,13 +2,8 @@
|
|||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../PerfCounter.h"
|
#include "../PerfCounter.h"
|
||||||
|
|
||||||
#include "Renderable.h"
|
|
||||||
#include "Memory/Framebuffer.h"
|
|
||||||
#include "../Scene/Components.h"
|
|
||||||
#include "../Scene/Scene.h"
|
#include "../Scene/Scene.h"
|
||||||
#include "Primitives/Camera.h"
|
#include "Framebuffer.h"
|
||||||
#include "OpenglAPI.h"
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
|
|
||||||
@ -35,182 +30,7 @@ namespace YoggieEngine {
|
|||||||
OpenGLApi::DrawTriangles(renderComponent);
|
OpenGLApi::DrawTriangles(renderComponent);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Render(Scene& scene, Camera MainCamera) {
|
void Render(Scene& scene, Camera MainCamera);
|
||||||
|
|
||||||
MainCamera.projection = glm::perspective(glm::radians(65.0f), ((float)width/(float)height), 0.0001f, 1000.0f);
|
|
||||||
int oldviewport[4];
|
|
||||||
glGetIntegerv(GL_VIEWPORT, oldviewport);
|
|
||||||
glViewport(0, 0, width, height);
|
|
||||||
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
// Render skybox if the scene has one
|
|
||||||
|
|
||||||
SkyboxShader.Use();
|
|
||||||
SkyboxShader.setUniformMat4("projection", MainCamera.projection);
|
|
||||||
SkyboxShader.setUniformMat4("view", glm::mat4(glm::mat3(MainCamera.view)));
|
|
||||||
|
|
||||||
if (!skyboxVAO) {
|
|
||||||
unsigned int VBO;
|
|
||||||
glGenVertexArrays(1, &skyboxVAO);
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glBindVertexArray(skyboxVAO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenGLApi::DrawCubeMap( skyboxVAO, skybox);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto renderables = scene.getReg().view<TransformComponent, Render3DComponent>();
|
|
||||||
gBufferShader.Use();
|
|
||||||
for (auto renderable : renderables) {
|
|
||||||
auto entity = Entity(renderable, &scene);
|
|
||||||
auto& renderComponent = entity.GetComponent<Render3DComponent>();
|
|
||||||
auto& transform = entity.GetComponent<TransformComponent>();
|
|
||||||
|
|
||||||
// Geometry pass
|
|
||||||
gBufferShader.setUniformVec3("Color", renderComponent.color);
|
|
||||||
gBufferShader.setUniformMat4("Model", transform.GetTransform());
|
|
||||||
gBufferShader.setUniformMat4("View", MainCamera.view);
|
|
||||||
gBufferShader.setUniformMat4("Projection", MainCamera.projection);
|
|
||||||
OpenGLApi::DrawTriangles(renderComponent);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Light pass
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
|
||||||
lightingPassShader.Use();
|
|
||||||
lightingPassShader.setUniformInt("gPosition", 0);
|
|
||||||
lightingPassShader.setUniformInt("gNormal", 1);
|
|
||||||
lightingPassShader.setUniformInt("gColorSpec", 2);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, gPosition);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, gNormal);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, gColorSpec);
|
|
||||||
|
|
||||||
auto lights = scene.getReg().view<LightComponent, TransformComponent>();
|
|
||||||
unsigned int lightnr = 0;
|
|
||||||
for (auto light : lights) {
|
|
||||||
auto lightComponent = Entity(light, &scene).GetComponent<LightComponent>();
|
|
||||||
auto transformComponent = Entity(light, &scene).GetComponent<TransformComponent>();
|
|
||||||
|
|
||||||
auto name = "lights[" + std::to_string(lightnr) + "]";
|
|
||||||
lightingPassShader.setUniformVec3(name + ".Position",transformComponent.Position );
|
|
||||||
lightingPassShader.setUniformVec3(name + ".Color", lightComponent.Color);
|
|
||||||
|
|
||||||
const float linear = 0.7f;
|
|
||||||
const float quadratic = 1.8f;
|
|
||||||
lightingPassShader.setUniformFloat(name + ".Linear", linear);
|
|
||||||
lightingPassShader.setUniformFloat(name + ".Quadratic", quadratic);
|
|
||||||
|
|
||||||
lightnr++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (quadVAO == 0)
|
|
||||||
{
|
|
||||||
float quadVertices[] = {
|
|
||||||
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
|
||||||
};
|
|
||||||
unsigned int quadVBO;
|
|
||||||
// setup plane VAO ;
|
|
||||||
glGenVertexArrays(1, &quadVAO);
|
|
||||||
glGenBuffers(1, &quadVBO);
|
|
||||||
glBindVertexArray(quadVAO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindVertexArray(quadVAO);
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
|
|
||||||
// Copy GBuffer
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
|
||||||
glBindFramebuffer(GL_DRAW_BUFFER, m_framebuffer.GetId());
|
|
||||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
|
||||||
|
|
||||||
|
|
||||||
if (transparentVAO == 0) {
|
|
||||||
unsigned int transparentVBO;
|
|
||||||
float transparentVertices[] = {
|
|
||||||
// positions // texture Coords (swapped y coordinates because texture is flipped upside down)
|
|
||||||
0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, -0.5f, 0.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, -0.5f, 0.0f, 1.0f, 0.0f,
|
|
||||||
|
|
||||||
0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, -0.5f, 0.0f, 1.0f, 0.0f,
|
|
||||||
1.0f, 0.5f, 0.0f, 1.0f, 1.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &transparentVAO);
|
|
||||||
glGenBuffers(1, &transparentVBO);
|
|
||||||
glBindVertexArray(transparentVAO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, transparentVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(transparentVertices), transparentVertices, GL_STATIC_DRAW);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
|
|
||||||
BlendingShader.Use();
|
|
||||||
glBindVertexArray(transparentVAO);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, grassTexture.GetID());
|
|
||||||
|
|
||||||
BlendingShader.setUniformMat4("V", MainCamera.view);
|
|
||||||
BlendingShader.setUniformMat4("P", MainCamera.projection);
|
|
||||||
for (unsigned int i = 0; i < vegetation.size(); i++) {
|
|
||||||
|
|
||||||
auto translation = glm::translate(glm::mat4(1.0f), vegetation[i]) ;
|
|
||||||
BlendingShader.setUniformMat4("M", translation);
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
glViewport(oldviewport[0], oldviewport[1], oldviewport[2], oldviewport[3]);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCurrentFrameBuffer(const Framebuffer& fb);
|
void setCurrentFrameBuffer(const Framebuffer& fb);
|
||||||
void setClearColor(const glm::vec3& ClearColor);
|
void setClearColor(const glm::vec3& ClearColor);
|
||||||
@ -238,7 +58,7 @@ namespace YoggieEngine {
|
|||||||
// blending
|
// blending
|
||||||
Shader BlendingShader;
|
Shader BlendingShader;
|
||||||
CubeMap skybox;
|
CubeMap skybox;
|
||||||
Texture grassTexture = Texture("build/Debug/Texture/grass.png");
|
Texture grassTexture;
|
||||||
|
|
||||||
unsigned int transparentVAO = 0;
|
unsigned int transparentVAO = 0;
|
||||||
unsigned int skyboxVAO = 0;
|
unsigned int skyboxVAO = 0;
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Assets/Asset.h"
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
class Shader {
|
class Shader : public Asset{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
char* readFile(const char* filePath);
|
char* readFile(const char* filePath);
|
||||||
|
|
||||||
|
|
||||||
|
AssetType GetType() override{ return AssetType::Shader; }
|
||||||
public:
|
public:
|
||||||
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
||||||
|
|
||||||
|
|
||||||
void Use() const;
|
void Use() const;
|
||||||
void setUniformMat4(std::string uniformName, const glm::mat4& matrix4)const;
|
void setUniformMat4(std::string uniformName, const glm::mat4& matrix4)const;
|
||||||
void setUniformVec4(std::string uniformName, const glm::vec4& vector4)const;
|
void setUniformVec4(std::string uniformName, const glm::vec4& vector4)const;
|
@ -2,7 +2,8 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
Texture::Texture(const std::string texturePath , bool Transparency) {
|
|
||||||
|
void Texture::Load(const std::string texturePath, bool Transparency) {
|
||||||
int channels;
|
int channels;
|
||||||
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
||||||
|
|
||||||
@ -30,7 +31,6 @@ namespace YoggieEngine {
|
|||||||
spdlog::error("Failed to load image ({0})", texturePath);
|
spdlog::error("Failed to load image ({0})", texturePath);
|
||||||
}
|
}
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::Bind() {
|
void Texture::Bind() {
|
@ -1,14 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Assets/Asset.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
class Texture {
|
class Texture : public Asset {
|
||||||
public:
|
public:
|
||||||
Texture() = default;
|
Texture() = default;
|
||||||
Texture(const std::string texturePath, bool Transparency = false);
|
void Load(const std::string texturePath, bool Transparency = false);
|
||||||
|
|
||||||
void Bind();
|
void Bind();
|
||||||
void Unbind();
|
void Unbind();
|
||||||
const unsigned int GetID() const { return Id; }
|
const unsigned int GetID() const { return Id; }
|
||||||
const ImVec2 getSize() { return {(float)width, (float)height}; }
|
const ImVec2 getSize() { return {(float)width, (float)height}; }
|
||||||
|
|
||||||
|
AssetType GetType() override { return AssetType::Texture; }
|
||||||
private:
|
private:
|
||||||
unsigned int Id;
|
unsigned int Id;
|
||||||
int width;
|
int width;
|
@ -1,29 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
class Layer {
|
class Layer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~Layer() { OnDestroy(); }
|
~Layer() { OnDestroy(); }
|
||||||
Layer() { OnCreate(); }
|
Layer() { OnCreate(); }
|
||||||
|
|
||||||
Layer(const std::string name )
|
|
||||||
: Name(name) {}
|
|
||||||
|
|
||||||
|
|
||||||
virtual void OnUpdate(){}
|
virtual void OnUpdate(){}
|
||||||
virtual void OnUI(){}
|
virtual void OnUI(){}
|
||||||
|
|
||||||
|
virtual bool OnKey(int key , int status ) {
|
||||||
|
spdlog::info( "Key {0} , {1}", key, status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnMouseButton(int button, int action) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnScroll(int xoffset, int yoffset) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnStartup(){}
|
virtual void OnStartup(){}
|
||||||
|
|
||||||
virtual void OnAttach() {}
|
virtual void OnAttach() {}
|
||||||
virtual void OnDetach() {}
|
virtual void OnDetach() {}
|
||||||
|
|
||||||
|
|
||||||
virtual void OnCreate() {}
|
virtual void OnCreate() {}
|
||||||
virtual void OnDestroy(){}
|
virtual void OnDestroy(){}
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::string Name;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
@ -1,10 +1,13 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include "PerfCounter.h"
|
#include "PerfCounter.h"
|
||||||
|
#include <YoggieEngine.h>
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
uint64_t EngineInstrumentation::GetPrecisionTime() {
|
uint64_t EngineInstrumentation::GetPrecisionTime() {
|
||||||
using namespace std::chrono; // REMINDER: This is kinda ugly but safes line width
|
using namespace std::chrono; // REMINDER: This is kinda ugly but safes line
|
||||||
return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
|
// width
|
||||||
|
return duration_cast<milliseconds>(
|
||||||
|
high_resolution_clock::now().time_since_epoch())
|
||||||
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineInstrumentation::PerfomanceSamplerInit() {
|
void EngineInstrumentation::PerfomanceSamplerInit() {
|
||||||
@ -14,51 +17,42 @@ namespace YoggieEngine {
|
|||||||
EngineInstrumentation::lastSampleTime = GetPrecisionTime();*/
|
EngineInstrumentation::lastSampleTime = GetPrecisionTime();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void EngineInstrumentation::Update() {
|
void EngineInstrumentation::Update() {
|
||||||
|
|
||||||
/* uint64_t MilliSecondsPast = GetPrecisionTime() - EngineInstrumentation::lastSampleTime;
|
/* uint64_t MilliSecondsPast = GetPrecisionTime() -
|
||||||
|
EngineInstrumentation::lastSampleTime;
|
||||||
|
|
||||||
if (MilliSecondsPast >= 1000) {
|
if (MilliSecondsPast >= 1000) {
|
||||||
|
|
||||||
EngineInstrumentation::frameTime = (float)1000 / EngineInstrumentation::frames;
|
EngineInstrumentation::frameTime = (float)1000 /
|
||||||
EngineInstrumentation::FPS = frames;
|
EngineInstrumentation::frames; EngineInstrumentation::FPS = frames;
|
||||||
EngineInstrumentation::frames = 0;
|
EngineInstrumentation::frames = 0;
|
||||||
EngineInstrumentation::lastSampleTime = GetPrecisionTime();
|
EngineInstrumentation::lastSampleTime =
|
||||||
|
GetPrecisionTime();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineInstrumentation::ShowStats() {
|
void EngineInstrumentation::ShowStats() {
|
||||||
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
|
// ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse |
|
||||||
|
//ImGuiWindowFlags_NoResize);
|
||||||
|
|
||||||
ImGui::Text("Currently not available");
|
// ImGui::Text("Currently not available");
|
||||||
/* ImGui::Text("FPS: %i", ES.FPS);
|
/* ImGui::Text("FPS: %i", ES.FPS);
|
||||||
ImGui::Text("Frame Time: %f", ES.frameTime);
|
ImGui::Text("Frame Time: %f", ES.frameTime);
|
||||||
ImGui::Text("Verts: %i", ES.verts);
|
ImGui::Text("Verts: %i", ES.verts);
|
||||||
ImGui::Text("Draw Calls: %i", ES.DC);
|
ImGui::Text("Draw Calls: %i", ES.DC);
|
||||||
*/
|
*/
|
||||||
ImGui::End();
|
// ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PerfSampler::PerfSampler(const std::string &name) : name(name) {
|
||||||
PerfSampler::PerfSampler(const std::string& name)
|
|
||||||
: name(name)
|
|
||||||
{
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
startTime = high_resolution_clock::now();
|
startTime = high_resolution_clock::now();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfSampler::~PerfSampler()
|
PerfSampler::~PerfSampler() { Stop(); }
|
||||||
{
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PerfSampler::Stop()
|
void PerfSampler::Stop() {
|
||||||
{
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
auto end = high_resolution_clock::now();
|
auto end = high_resolution_clock::now();
|
||||||
auto durationInuSeconds =
|
auto durationInuSeconds =
|
||||||
@ -67,6 +61,7 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
auto ms = durationInuSeconds * 0.001f;
|
auto ms = durationInuSeconds * 0.001f;
|
||||||
|
|
||||||
// std::cout << "[" << name << "]" << "Took: " << durationInuSeconds << " us (" << ms << " ms)" << std::endl;
|
// std::cout << "[" << name << "]" << "Took: " << durationInuSeconds << "
|
||||||
}
|
//us (" << ms << " ms)" << std::endl;
|
||||||
}
|
}
|
||||||
|
} // namespace YoggieEngine
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../EventSystem/Event.h"
|
|
||||||
#include "../EventSystem/EventListener.h"
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
class NativeWindow {
|
class NativeWindow {
|
||||||
|
|
||||||
|
@ -18,32 +18,38 @@ namespace YoggieEngine {
|
|||||||
glm::mat4 LocalTransform = glm::mat4(1.0f);
|
glm::mat4 LocalTransform = glm::mat4(1.0f);
|
||||||
|
|
||||||
glm::mat4 GetTransform() const {
|
glm::mat4 GetTransform() const {
|
||||||
|
glm::mat4 rotation = glm::toMat4(glm::quat(Rotation));
|
||||||
|
|
||||||
|
auto transform = glm::translate(glm::mat4(1.0f), Position)* rotation
|
||||||
|
* glm::scale(glm::mat4(1.0f), Scale);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)) * glm::scale(glm::mat4(1.0f), Scale);
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Decompose(glm::mat4 transformationMatrix) {
|
void Decompose(glm::mat4& transformationMatrix) {
|
||||||
glm::mat4& tm = transformationMatrix;
|
|
||||||
|
|
||||||
|
|
||||||
auto& a = tm[0][0];
|
|
||||||
auto& b = tm[1][0];
|
|
||||||
auto& c = tm[2][0];
|
|
||||||
auto& d = tm[3][0];
|
|
||||||
|
|
||||||
auto& e = tm[0][1];
|
auto& a = transformationMatrix[0][0];
|
||||||
auto& f = tm[1][1];
|
auto& b = transformationMatrix[1][0];
|
||||||
auto& g = tm[2][1];
|
auto& c = transformationMatrix[2][0];
|
||||||
auto& h = tm[3][1];
|
auto& d = transformationMatrix[3][0];
|
||||||
|
|
||||||
auto& i = tm[0][2];
|
auto& e = transformationMatrix[0][1];
|
||||||
auto& j = tm[1][2];
|
auto& f = transformationMatrix[1][1];
|
||||||
auto& k = tm[2][2];
|
auto& g = transformationMatrix[2][1];
|
||||||
auto& l = tm[3][2];
|
auto& h = transformationMatrix[3][1];
|
||||||
|
|
||||||
Position = glm::vec3(d, h, l);
|
auto& i = transformationMatrix[0][2];
|
||||||
|
auto& j = transformationMatrix[1][2];
|
||||||
|
auto& k = transformationMatrix[2][2];
|
||||||
|
auto& l = transformationMatrix[3][2];
|
||||||
|
|
||||||
|
Position = glm::vec3(transformationMatrix[3]);
|
||||||
|
|
||||||
|
// Remove the position from the matrix
|
||||||
d = 0;
|
d = 0;
|
||||||
h = 0;
|
h = 0;
|
||||||
l = 0;
|
l = 0;
|
||||||
@ -54,6 +60,7 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
Scale = glm::vec3(sx, sy, sz);
|
Scale = glm::vec3(sx, sy, sz);
|
||||||
|
|
||||||
|
// Remove the scale from the matrix;
|
||||||
a/= sx;
|
a/= sx;
|
||||||
e /= sx;
|
e /= sx;
|
||||||
i /= sx;
|
i /= sx;
|
||||||
@ -67,12 +74,12 @@ namespace YoggieEngine {
|
|||||||
k /= sz;
|
k /= sz;
|
||||||
|
|
||||||
|
|
||||||
auto w = glm::sqrt(1 + tm[0][0] + tm[1][1] + tm[2][2]) / 2;
|
auto w = glm::sqrt(1 + transformationMatrix[0][0] + transformationMatrix[1][1] + transformationMatrix[2][2]) / 2;
|
||||||
|
|
||||||
|
|
||||||
auto x = (tm[2][1] - tm[1][2]) / (4 * w);
|
auto x = (transformationMatrix[2][1] - transformationMatrix[1][2]) / (4 * w);
|
||||||
auto y = (tm[0][2] - tm[2][0]) / (4 * w);
|
auto y = (transformationMatrix[0][2] - transformationMatrix[2][0]) / (4 * w);
|
||||||
auto z = (tm[1][0] - tm[0][1]) / (4 * w);
|
auto z = (transformationMatrix[1][0] - transformationMatrix[0][1]) / (4 * w);
|
||||||
|
|
||||||
|
|
||||||
auto rot = glm::quat(w, x, y, z);
|
auto rot = glm::quat(w, x, y, z);
|
||||||
@ -127,7 +134,6 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
|
|
||||||
struct Render3DComponent {
|
struct Render3DComponent {
|
||||||
Renderable* renderable;
|
|
||||||
|
|
||||||
unsigned int VAO = 0;
|
unsigned int VAO = 0;
|
||||||
unsigned int IBO = 0;
|
unsigned int IBO = 0;
|
||||||
|
@ -31,61 +31,11 @@ namespace YoggieEngine{
|
|||||||
void Scene::Start()
|
void Scene::Start()
|
||||||
{
|
{
|
||||||
// Execute start functions in scripts etc....
|
// Execute start functions in scripts etc....
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::Update()
|
void Scene::Update()
|
||||||
{
|
{
|
||||||
// Execute Update functions in scripts etc....
|
// Execute Update functions in scripts etc....
|
||||||
|
|
||||||
// Update transforms
|
|
||||||
|
|
||||||
auto& transforms = m_registry.view<TransformComponent>();
|
|
||||||
transforms.each([&](auto ent, TransformComponent& transform) {
|
|
||||||
|
|
||||||
glm::mat4 rotationX =
|
|
||||||
glm::rotate(
|
|
||||||
glm::mat4(1.0f),
|
|
||||||
glm::radians(transform.Rotation.x),
|
|
||||||
glm::vec3(1.f, 0.f, 0.0f)
|
|
||||||
);
|
|
||||||
glm::mat4 rotationY =
|
|
||||||
glm::rotate(
|
|
||||||
glm::mat4(1.0f),
|
|
||||||
glm::radians(transform.Rotation.y),
|
|
||||||
glm::vec3(0.f, 1.f, 0.0f)
|
|
||||||
);
|
|
||||||
glm::mat4 rotationZ =
|
|
||||||
glm::rotate(
|
|
||||||
glm::mat4(1.0f),
|
|
||||||
transform.Rotation.z,
|
|
||||||
glm::vec3(0.f, 0.f, 1.0f)
|
|
||||||
);
|
|
||||||
|
|
||||||
glm::mat4 rotationMatrix = rotationY * rotationX * rotationZ;
|
|
||||||
glm::mat4 translationMatrix = glm::translate(glm::mat4(1.0f), transform.Position);
|
|
||||||
glm::mat4 ScaleMatrix = glm::scale(glm::mat4(1.0f), transform.Scale);
|
|
||||||
|
|
||||||
Entity entity( ent, this );
|
|
||||||
|
|
||||||
|
|
||||||
if (entity.HasComponent<RelationComponent>())
|
|
||||||
{
|
|
||||||
auto& entityRelation = entity.GetComponent<RelationComponent>();
|
|
||||||
Entity parent = entityRelation.Parent;
|
|
||||||
TransformComponent parentTransform = parent.GetComponent<TransformComponent>();
|
|
||||||
glm::mat4 Model = translationMatrix * rotationMatrix * ScaleMatrix;
|
|
||||||
transform.LocalTransform = parentTransform.LocalTransform * Model;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
transform.LocalTransform = translationMatrix * rotationMatrix * ScaleMatrix;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::FixedUpdate()
|
void Scene::FixedUpdate()
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <YoggieEngine.h>
|
||||||
#include "SceneSerializer.h"
|
#include "SceneSerializer.h"
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
class UUID {
|
|
||||||
|
|
||||||
public:
|
|
||||||
static uint64_t Generate()
|
|
||||||
{
|
|
||||||
return ++last;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static uint64_t last ;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
@ -33,19 +33,16 @@ extern "C"
|
|||||||
// Main library stuff
|
// Main library stuff
|
||||||
#include "Platform/Platform.h"
|
#include "Platform/Platform.h"
|
||||||
|
|
||||||
#include "Graphics/Primitives/Mesh.h"
|
#include "Graphics/Mesh.h"
|
||||||
#include "Graphics/Primitives/Shader.h"
|
#include "Graphics/Shader.h"
|
||||||
#include "Graphics/Primitives/Texture.h"
|
#include "Graphics/Texture.h"
|
||||||
#include "Graphics/Primitives/CubeMap.h"
|
#include "Graphics/CubeMap.h"
|
||||||
#include "Graphics/Primitives/Camera.h"
|
#include "Graphics/Camera.h"
|
||||||
#include "Graphics/Primitives/Material.h"
|
#include "Graphics/Material.h"
|
||||||
#include "Graphics/Renderer.h"
|
#include "Graphics/Renderer.h"
|
||||||
|
|
||||||
#include "Physics/Physics.h"
|
#include "Physics/Physics.h"
|
||||||
|
|
||||||
#include "EventSystem/EventEmitter.h"
|
|
||||||
#include "EventSystem/EventListener.h"
|
|
||||||
|
|
||||||
#include "Input/Keyboard.h"
|
#include "Input/Keyboard.h"
|
||||||
#include "Input/InputManager.h"
|
#include "Input/InputManager.h"
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
@echo off
|
|
||||||
echo Clean up ..
|
|
||||||
REM Does nothing for now
|
|
||||||
REM In the future we might want to remove certain files, if they exist, when re-generating the solution
|
|
||||||
echo Creating Solution for Yoggie engine...
|
|
||||||
|
|
||||||
.\tools\premake5.exe vs2022
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pause
|
|
33
libraries.cmake
Normal file
33
libraries.cmake
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
add_library( thirdparty_tools INTERFACE)
|
||||||
|
add_subdirectory(libs/ImGui)
|
||||||
|
target_link_directories(thirdparty_tools INTERFACE
|
||||||
|
"libs/glfw/build/src"
|
||||||
|
"libs/physx/physx/bin/win.x86_64.vc142.mt/release"
|
||||||
|
"libs/nativefiledialog/build/lib/Release/x64"
|
||||||
|
"libs/googletest/build/lib/Debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(thirdparty_tools INTERFACE
|
||||||
|
nfd
|
||||||
|
YoggieEngine
|
||||||
|
)
|
||||||
|
target_include_directories(thirdparty_tools INTERFACE
|
||||||
|
"YoggieEngine/src"
|
||||||
|
"libs/spdlog/include"
|
||||||
|
"libs/assimp/include"
|
||||||
|
"libs/glm"
|
||||||
|
"libs/entt/src"
|
||||||
|
"libs/yaml-cpp/include"
|
||||||
|
"libs/mINI/src"
|
||||||
|
"libs/googletest/googletest/include"
|
||||||
|
"libs/glad/include"
|
||||||
|
"libs/glfw/include"
|
||||||
|
"libs/glew/include"
|
||||||
|
"libs/lua/include"
|
||||||
|
"libs/guizmo"
|
||||||
|
"libs/nativefiledialog/src/include"
|
||||||
|
"libs/ImGui"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
|||||||
incfolder = {}
|
|
||||||
|
|
||||||
--Utils
|
|
||||||
incfolder["spdlog"] = "%{wks.location}/libs/spdlog/include"
|
|
||||||
incfolder["assimp"] = "%{wks.location}/libs/assimp/include"
|
|
||||||
incfolder["glm"] = "%{wks.location}/libs/glm"
|
|
||||||
incfolder["entt"] = "%{wks.location}/libs/entt/src"
|
|
||||||
incfolder["yamlcpp"] = "%{wks.location}/libs/yaml-cpp/include"
|
|
||||||
incfolder["mINI"] = "%{wks.location}/libs/mINI/src"
|
|
||||||
incfolder["GoogleTest"] = "%{wks.location}/libs/googletest/googletest/include"
|
|
||||||
|
|
||||||
-- Graphics
|
|
||||||
incfolder["glad"] = "%{wks.location}/libs/glad/include"
|
|
||||||
incfolder["glfw"] = "%{wks.location}/libs/glfw/include"
|
|
||||||
incfolder["glew"] = "%{wks.location}/libs/glew/include"
|
|
||||||
-- Physics
|
|
||||||
|
|
||||||
-- Scripting
|
|
||||||
incfolder["lua"] = "%{wks.location}/libs/lua/include"
|
|
||||||
|
|
||||||
|
|
||||||
-- Audio
|
|
||||||
incfolder["gorillaaudio"] = "%{wks.location}/libs/GorillaAudio/include"
|
|
||||||
|
|
||||||
-- Immediate Mode GUI
|
|
||||||
incfolder["imgui"] = "%{wks.location}/libs/ImGui"
|
|
||||||
incfolder["imguizmo"] = "%{wks.location}/libs/guizmo"
|
|
||||||
incfolder["nativefiledialog"] = "%{wks.location}/libs/nativefiledialog/src/include"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
staticlib = {}
|
|
||||||
|
|
||||||
staticlib["yoggie"] = "Yoggie/build/Debug"
|
|
||||||
staticlib["nativefiledialog"]= "%{wks.location}/libs/nativefiledialog/build/lib/Release/x64"
|
|
||||||
staticlib["GoogleTest"] = "%{wks.location}/libs/googletest/build/lib/Debug"
|
|
Submodule libs/ImGui updated: d666a1d473...c191faf0ba
1
libs/googletest
Submodule
1
libs/googletest
Submodule
Submodule libs/googletest added at d6fb5e3bf7
44
premake5.lua
44
premake5.lua
@ -1,44 +0,0 @@
|
|||||||
include("libraries")
|
|
||||||
print("Using Premake version ", _PREMAKE_VERSION)
|
|
||||||
|
|
||||||
workspace "Yoggie GameEngine"
|
|
||||||
configurations { "Debug", "Release" }
|
|
||||||
|
|
||||||
language "C++"
|
|
||||||
cppdialect "C++17"
|
|
||||||
architecture "x86_64"
|
|
||||||
|
|
||||||
targetdir "%{wks.location}/libs/%{prj.name}/build/%{cfg.buildcfg}"
|
|
||||||
objdir "%{wks.location}/libs/%{prj.name}/build/%{cfg.buildcfg}/intermediates/"
|
|
||||||
|
|
||||||
startproject("Editor")
|
|
||||||
|
|
||||||
|
|
||||||
defines{
|
|
||||||
" _CRT_SECURE_NO_WARNINGS",
|
|
||||||
"GLFW_STATIC"
|
|
||||||
}
|
|
||||||
|
|
||||||
filter "configurations:Debug"
|
|
||||||
defines {"DEBUG"}
|
|
||||||
symbols "On"
|
|
||||||
|
|
||||||
filter "configurations:Release"
|
|
||||||
defines {"NDEBUG"}
|
|
||||||
optimize "On"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include("./YoggieEngine")
|
|
||||||
include ("./Editor")
|
|
||||||
include ("./Tests")
|
|
||||||
|
|
||||||
group("Other")
|
|
||||||
include("./SandboxApp")
|
|
||||||
|
|
||||||
group("Libraries")
|
|
||||||
include('libs/ImGui')
|
|
||||||
include("libs/guizmo")
|
|
||||||
include("libs/yaml-cpp")
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user