Compare commits
	
		
			4 Commits
		
	
	
		
			89f5b1497f
			...
			d8627d0357
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d8627d0357 | |||
| ec8045c4f4 | |||
| 042dc3a457 | |||
| 28927d9a4e | 
| @ -2,6 +2,7 @@ | ||||
| #include "../../YoggieEngine/src/YoggieEngine.h" | ||||
| #include <filesystem> | ||||
| #include <string> | ||||
| #include "uuid.h" | ||||
|  | ||||
| enum class ASSET_TYPE { | ||||
| 	Unknown = -1, | ||||
| @ -13,34 +14,12 @@ enum class ASSET_TYPE { | ||||
| class Asset { | ||||
| public: | ||||
| 	Asset(const char* name):  name(name) {} | ||||
| 	uuid::v4::UUID id = uuid::v4::UUID::New(); | ||||
|  | ||||
| 	virtual ASSET_TYPE GetType() { return ASSET_TYPE::Unknown; } | ||||
| 	const char* GetName() const { return name.c_str(); } | ||||
| 	bool isFolder = false ; | ||||
| protected: | ||||
| 	std::string name; | ||||
|  | ||||
| }; | ||||
|  | ||||
| class MeshAsset : Asset { | ||||
| public: | ||||
| 	MeshAsset(YoggieEngine::Mesh mesh) : Asset("New MeshAsset"), mesh(mesh) {} | ||||
| 	ASSET_TYPE  GetType() override { return ASSET_TYPE::Mesh; } | ||||
| private: | ||||
| 	YoggieEngine::Mesh& mesh; | ||||
| }; | ||||
|  | ||||
| class TextureAsset : Asset { | ||||
| public: | ||||
| 	TextureAsset (YoggieEngine::Texture texture): Asset("New TextureAsset"), texture(texture) {} | ||||
| 	ASSET_TYPE GetType() override { return ASSET_TYPE::Texture; } | ||||
| private: | ||||
| 	YoggieEngine::Texture& texture; | ||||
| }; | ||||
|  | ||||
| class MaterialAsset : Asset { | ||||
| public: | ||||
| 	MaterialAsset ()  : Asset("New MaterialAsset"){} | ||||
| 	ASSET_TYPE GetType() override { return ASSET_TYPE::Material; } | ||||
| private: | ||||
|  | ||||
| 	 | ||||
| }; | ||||
| @ -5,24 +5,22 @@ | ||||
|  | ||||
| class AssetFinder : EditorWindow { | ||||
| public: | ||||
|     AssetFinder() : EditorWindow("Assets") {} | ||||
|     AssetFinder() : EditorWindow("Assets"), | ||||
|                     folderIcon ("rsc/FolderIcon.png"), | ||||
|                     assetIcon ("rsc/AssetIcon.png") | ||||
|     {} | ||||
|  | ||||
|     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)); | ||||
|  | ||||
|             YoggieEngine::Texture folderIcon = YoggieEngine::Texture("rsc/folderIcon.png"); | ||||
|             YoggieEngine::Texture assetIcon = YoggieEngine::Texture("rsc/assetIcon.png"); | ||||
|  | ||||
|  | ||||
|             /* | ||||
|             int row = 0; | ||||
|             int column = 0; | ||||
|             for (auto& asset : AssetManager::assets) { | ||||
| @ -52,6 +50,7 @@ public: | ||||
|  | ||||
|                 column++; | ||||
|             } | ||||
|             */ | ||||
|  | ||||
|  | ||||
|             ImGui::PopStyleColor(3); | ||||
| @ -64,5 +63,10 @@ public: | ||||
|  | ||||
| private: | ||||
|     int iconSize = 60; | ||||
|     int maxColumns = 3; | ||||
|  | ||||
|     YoggieEngine::Texture folderIcon; | ||||
|     YoggieEngine::Texture assetIcon; | ||||
|  | ||||
| }; | ||||
|  | ||||
|  | ||||
							
								
								
									
										9
									
								
								Editor/src/AssetManagement/AssetLoaders/AssetLoader.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								Editor/src/AssetManagement/AssetLoaders/AssetLoader.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| #pragma once | ||||
| #include <filesystem> | ||||
| #include "../Asset.h" | ||||
| class AssetLoader { | ||||
| public: | ||||
| 	virtual Asset LoadAsset(std::filesystem::path& path) = 0; | ||||
| 	// virtual void PackageAsset(Asset& asset ) = 0;  | ||||
|  | ||||
| }; | ||||
							
								
								
									
										102
									
								
								Editor/src/AssetManagement/AssetLoaders/ModelLoader.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								Editor/src/AssetManagement/AssetLoaders/ModelLoader.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,102 @@ | ||||
| #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::debug("Loading meshes!"); | ||||
|  | ||||
| 	auto meshes = processNode(currentNode, scene); | ||||
|  | ||||
| 	return Asset("Mesh"); | ||||
|  | ||||
|  | ||||
|  | ||||
| } | ||||
							
								
								
									
										10
									
								
								Editor/src/AssetManagement/AssetLoaders/ModelLoader.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Editor/src/AssetManagement/AssetLoaders/ModelLoader.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| #pragma once | ||||
| #include "AssetLoader.h" | ||||
|  | ||||
| class  ModelLoader : AssetLoader { | ||||
|  | ||||
| 	Asset LoadAsset(std::filesystem::path& path); | ||||
|  | ||||
|  | ||||
|  | ||||
| }; | ||||
| @ -1,42 +1,34 @@ | ||||
| #include "AssetManager.h" | ||||
| #include "../../YoggieEngine/src/AssetManager/ModelImporter.h" | ||||
|  | ||||
| #include <iostream> | ||||
| #include <fstream> | ||||
| #include <spdlog/spdlog.h> | ||||
|  | ||||
| std::vector<Asset> AssetManager::assets; | ||||
| std::filesystem::path AssetManager::currentPath; | ||||
| #include "AssetLoaders/ModelLoader.h" | ||||
| /* | ||||
| * this is still a very naive approach to the asset manager | ||||
| */ | ||||
|  | ||||
| void AssetManager::Init()  | ||||
| {  | ||||
| 	assets = std::vector<Asset>(); | ||||
| 	currentPath = std::filesystem::path(".");  | ||||
| } | ||||
|  | ||||
| void AssetManager::BuildAssetView() | ||||
| { | ||||
| 	if (currentPath.empty()) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	for (auto& dir_entry : std::filesystem::directory_iterator(currentPath)) | ||||
| 	{ | ||||
| 		auto asset = Asset(dir_entry.path().filename().string().c_str()); | ||||
| 	 | ||||
| 		if (dir_entry.is_directory()) { | ||||
| 			asset.isFolder = true; | ||||
| 		} | ||||
| 		 | ||||
| 		assets.push_back(asset); | ||||
| 	} | ||||
| //	Assets =  std::map<uuid::v4::UUID&, Asset>(); | ||||
| 	modelLoader = ModelLoader(); | ||||
|  | ||||
| } | ||||
|  | ||||
| void AssetManager::setAssetPath(std::filesystem::path path)  | ||||
| {  | ||||
| 	currentPath = path;  | ||||
| void AssetManager::RegisterAsset(Asset& asset)  | ||||
| { | ||||
| //	Assets.try_emplace(asset.id, asset); | ||||
| } | ||||
|  | ||||
|  | ||||
| void AssetManager::UnregisterAsset(Asset& asset) { | ||||
| //	auto old = Assets[asset.id]; | ||||
| //	Assets[asset.id] = NULL; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path assetPath) | ||||
| { | ||||
| 	YoggieEngine::Mesh* imported = nullptr; | ||||
| @ -100,7 +92,8 @@ YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path | ||||
| YoggieEngine::Renderable* AssetManager::LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder) | ||||
| { | ||||
|  | ||||
| 	auto model = (YoggieEngine::ModelImporter()).Import(srcPath.string()); | ||||
| 	/* | ||||
| 	* 	auto model = (YoggieEngine::ModelImporter()).Import(srcPath.string()); | ||||
| 	YoggieEngine::Mesh* exportMesh = model->renderable->mesh; | ||||
| 	std::filesystem::path MeshFileName = assetFolder / srcPath.filename().replace_extension(".mesh"); | ||||
| 	std::cout << "Save path: " << MeshFileName << std::endl; | ||||
| @ -145,4 +138,6 @@ YoggieEngine::Renderable* AssetManager::LoadFromSource(const std::filesystem::pa | ||||
|  | ||||
| 	return model->renderable; | ||||
|  | ||||
| 	*/ | ||||
| 	return nullptr; | ||||
| } | ||||
|  | ||||
| @ -1,20 +1,23 @@ | ||||
| #pragma once | ||||
| #include <vector> | ||||
| #include "Asset.h" | ||||
| #include "AssetLoaders/ModelLoader.h" | ||||
| #include "uuid.h" | ||||
|  | ||||
| class AssetManager { | ||||
| public: | ||||
|  | ||||
| 	static void Init(); | ||||
| 	static void BuildAssetView(); | ||||
| 	static void setAssetPath(std::filesystem::path path); | ||||
| 	void Init(); | ||||
| 	 | ||||
| 	void RegisterAsset(Asset& asset); | ||||
| 	void UnregisterAsset(Asset& asset); | ||||
|  | ||||
|  | ||||
| 	static YoggieEngine::Mesh* LoadFromAssetFile(const std::filesystem::path assetPath); | ||||
| 	static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder); | ||||
| 	 | ||||
| 	static std::vector<Asset> assets ; | ||||
|  | ||||
| private: | ||||
| 	static std::filesystem::path currentPath; | ||||
| private:  | ||||
| 	std::map<uuid::v4::UUID , Asset> Assets; | ||||
| 	ModelLoader modelLoader; | ||||
|  | ||||
| }; | ||||
							
								
								
									
										63
									
								
								Editor/src/AssetManagement/uuid.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Editor/src/AssetManagement/uuid.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| /* | ||||
| *  | ||||
| * SOURCE: https://github.com/rkg82/uuid-v4/blob/main/uuid/v4/uuid.h | ||||
| * | ||||
| */ | ||||
| #ifndef __UUID__ | ||||
| #define __UUID__ | ||||
|  | ||||
| #include <random> | ||||
| #include <string> | ||||
|  | ||||
| namespace uuid::v4 | ||||
| { | ||||
|     // Encaasulate the genaeration of a Version 4 UUID object | ||||
|     // A Version 4 UUID is a universally unique identifier that is generated using random numbers. | ||||
|     class UUID | ||||
|     { | ||||
|     public: | ||||
|         // Factory method for creating UUID object. | ||||
|         static UUID New() | ||||
|         { | ||||
|             UUID uuid; | ||||
|             std::random_device rd; | ||||
|             std::mt19937 engine{ rd() }; | ||||
|             std::uniform_int_distribution<int> dist{ 0, 256 }; //Limits of the interval | ||||
|  | ||||
|             for (int index = 0; index < 16; ++index) | ||||
|             { | ||||
|                 uuid._data[index] = (unsigned char)dist(engine); | ||||
|             } | ||||
|  | ||||
|             uuid._data[6] = ((uuid._data[6] & 0x0f) | 0x40); // Version 4 | ||||
|             uuid._data[8] = ((uuid._data[8] & 0x3f) | 0x80); // Variant is 10 | ||||
|  | ||||
|             return uuid; | ||||
|         } | ||||
|  | ||||
|         // Returns UUID as formatted string | ||||
|         std::string String() | ||||
|         { | ||||
|             // Formats to "0065e7d7-418c-4da4-b4d6-b54b6cf7466a" | ||||
|             char buffer[256] = { 0 }; | ||||
|             std::snprintf(buffer, 255, | ||||
|                 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | ||||
|                 _data[0], _data[1], _data[2], _data[3], | ||||
|                 _data[4], _data[5], | ||||
|                 _data[6], _data[7], | ||||
|                 _data[8], _data[9], | ||||
|                 _data[10], _data[11], _data[12], _data[13], _data[14], _data[15]); | ||||
|  | ||||
|             std::string uuid = buffer; | ||||
|  | ||||
|             return uuid; | ||||
|         } | ||||
|  | ||||
|     private: | ||||
|         UUID() {} | ||||
|  | ||||
|         unsigned char _data[16] = { 0 }; | ||||
|     }; | ||||
| }; | ||||
|  | ||||
| #endif // #ifndef __UUID__ | ||||
| @ -19,8 +19,8 @@ void MainMenuBar::ApplicationMenu(Project& project) { | ||||
|             switch (result) { | ||||
|             case(NFD_OKAY): | ||||
|                 Project::LoadProject(path, project); | ||||
|                 AssetManager::setAssetPath(project.GetProjectDirectory()); | ||||
|                 AssetManager::BuildAssetView(); | ||||
|                 //AssetManager::setAssetPath(project.GetProjectDirectory()); | ||||
|                 //AssetManager::BuildAssetView(); | ||||
|                 break; | ||||
|             case(NFD_CANCEL): | ||||
|                 break; | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| #include "Inspector.h" | ||||
|  | ||||
| #include "../TransformVec3.h" | ||||
|  | ||||
| void Inspector::Draw()  | ||||
| { | ||||
| @ -8,24 +8,40 @@ void Inspector::Draw() | ||||
|         ShowComponents(); | ||||
|     } | ||||
| }         | ||||
| void AddComponent(YoggieEngine::Entity selected , int i) { | ||||
|     switch (i) { | ||||
|     case 0: | ||||
|         selected.AddComponent<YoggieEngine::ScriptComponent>(); | ||||
|         break; | ||||
|     case 1: | ||||
|         selected.AddComponent<YoggieEngine::CameraComponent>(); | ||||
|         break; | ||||
|     case 2: | ||||
|         selected.AddComponent<YoggieEngine::LightComponent>(); | ||||
|         break; | ||||
|     case 3: | ||||
|         selected.AddComponent<YoggieEngine::Render3DComponent>(); | ||||
|     default: | ||||
|  | ||||
|         break; | ||||
|     } | ||||
| } | ||||
|  | ||||
| void Inspector::AddComponentDropDown()  | ||||
| { | ||||
|     static char* names[] = { "Script Component", "Camera Component", "Light Component" }; | ||||
|     static char* names[] = { "Script Component", "Camera Component", "Light Component", "Render3D"}; | ||||
|     if (ImGui::Button("Add Component")) | ||||
|         ImGui::OpenPopup("Component picker"); | ||||
|  | ||||
|     ImGui::SameLine(); | ||||
|     if (ImGui::BeginPopup("Component picker")) { | ||||
|  | ||||
|         for (int i = 0; i < IM_ARRAYSIZE(names); i++) | ||||
|             if (ImGui::MenuItem(names[i])) { | ||||
|                 std::cout << "Add a " << names[i] << " to " | ||||
|                     << selected.GetComponent<YoggieEngine::IdentifierComponent>().name << std::endl; | ||||
|             } | ||||
|  | ||||
|         for (int i = 0; i < IM_ARRAYSIZE(names); i++) { | ||||
|             if (ImGui::MenuItem(names[i])) | ||||
|                 AddComponent(selected, i); | ||||
|         } | ||||
|         ImGui::EndPopup(); | ||||
|  | ||||
|     } | ||||
|     ImGui::NewLine(); | ||||
| } | ||||
| @ -40,9 +56,18 @@ void Inspector::ShowComponents() | ||||
|     if (selected.HasComponent<YoggieEngine::TransformComponent>()) { | ||||
|         auto& transform = selected.GetComponent<YoggieEngine::TransformComponent>(); | ||||
|         if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) { | ||||
| /* | ||||
|             ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f); | ||||
|             ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f); | ||||
|             ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f); | ||||
| */ | ||||
|             auto something = glm::value_ptr(transform.Position); | ||||
|  | ||||
|             ImGuiExtension::TransformVec3("Position", transform.Position); | ||||
|             ImGuiExtension::TransformVec3("Rotation", transform.Rotation); | ||||
|             ImGuiExtension::TransformVec3("Scale", transform.Scale); | ||||
|  | ||||
|  | ||||
|         } | ||||
|         if (selected.HasComponent<YoggieEngine::RelationComponent>()) { | ||||
|             ImGui::Text("Has relation"); | ||||
| @ -54,13 +79,35 @@ void Inspector::ShowComponents() | ||||
|  | ||||
|     if (selected.HasComponent<YoggieEngine::Render3DComponent>()) { | ||||
|         auto& render3d = selected.GetComponent<YoggieEngine::Render3DComponent>(); | ||||
|         const char* AssetNames[]{ "Asset1" , "Asset2" }; | ||||
|         if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) { | ||||
|  | ||||
|             if (ImGui::Button("Select Renderable Asset")) | ||||
|                 ImGui::OpenPopup("Renderable_list_popup"); | ||||
|             ImGui::SameLine(); | ||||
|             ImGui::TextUnformatted(render3d.mesh.elements.empty() ? "<None>" : "ASSET_GUID_OR_ID"); | ||||
|             if (ImGui::BeginPopup("Renderable_list_popup")) { | ||||
|                 ImGui::Text("None"); | ||||
|                 ImGui::Separator(); | ||||
|                 for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) { | ||||
|                     if(ImGui::Selectable(AssetNames[i])) | ||||
|                     { } | ||||
|                 } | ||||
|                 ImGui::EndPopup(); | ||||
|  | ||||
|             } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|             ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color)); | ||||
|  | ||||
|             ImGui::Checkbox("Use static rendering:", &render3d.isStatic); | ||||
|         } | ||||
|     } | ||||
|     static bool deferred = true; | ||||
|      | ||||
|      | ||||
|     if (selected.HasComponent<YoggieEngine::LightComponent>()) { | ||||
|         auto& light = selected.GetComponent<YoggieEngine::LightComponent>(); | ||||
|         if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) { | ||||
|  | ||||
							
								
								
									
										59
									
								
								Editor/src/TransformVec3.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								Editor/src/TransformVec3.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,59 @@ | ||||
| #pragma once | ||||
| #include <imgui_widgets.cpp> | ||||
| #include <glm/glm.hpp> | ||||
| namespace ImGuiExtension { | ||||
|  | ||||
|  | ||||
|     void  TransformVec3(const char* label, glm::vec3& vector) { | ||||
|  | ||||
|         ImGui::PushID(label); | ||||
|         ImGui::Columns(2); | ||||
|         ImGui::SetColumnWidth(0, 100.0f); | ||||
|         ImGui::Text(label); | ||||
|  | ||||
|         ImGui::NextColumn(); | ||||
|  | ||||
|         ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); | ||||
|         ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 }); | ||||
|  | ||||
|         ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f }); | ||||
|         ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f,0.2f,0.2f, 1.0f }); | ||||
|         ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.8f,0.1f,0.15f, 1.0f }); | ||||
|         if (ImGui::Button("X")) | ||||
|             vector.x = 0; | ||||
|         ImGui::PopStyleColor(3); | ||||
|  | ||||
|         ImGui::SameLine(); | ||||
|         ImGui::DragFloat("##X", &glm::value_ptr(vector)[0], 0.1f, 0.0f, 0.0f, "%.2f"); | ||||
|         ImGui::PopItemWidth(); | ||||
|         ImGui::SameLine(); | ||||
|  | ||||
|         ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f }); | ||||
|         ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.3f,0.8f,0.3f, 1.0f }); | ||||
|         ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.2f,0.7f,0.2f, 1.0f }); | ||||
|         if (ImGui::Button("Y")) | ||||
|             vector.y = 0; | ||||
|         ImGui::PopStyleColor(3); | ||||
|  | ||||
|         ImGui::SameLine(); | ||||
|         ImGui::DragFloat("##Y", &glm::value_ptr(vector)[1], 0.1f, 0.0f, 0.0f, "%.2f"); | ||||
|         ImGui::PopItemWidth(); | ||||
|         ImGui::SameLine(); | ||||
|  | ||||
|         ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.1f, 0.25f, 0.8f, 1.0f }); | ||||
|         ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.2f,0.35f,0.9f, 1.0f }); | ||||
|         ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.1f,0.25f,0.8f, 1.0f }); | ||||
|         if (ImGui::Button("Z")) | ||||
|             vector.z = 0; | ||||
|         ImGui::PopStyleColor(3); | ||||
|  | ||||
|         ImGui::SameLine(); | ||||
|         ImGui::DragFloat("##Z", &glm::value_ptr(vector)[2], 0.1f, 0.0f, 0.0f, "%.2f"); | ||||
|         ImGui::PopItemWidth(); | ||||
|         ImGui::PopStyleVar(); | ||||
|  | ||||
|         ImGui::Columns(1); | ||||
|         ImGui::PopID(); | ||||
|  | ||||
|     } | ||||
| } | ||||
| @ -12,6 +12,7 @@ | ||||
| #include "PropertyPanels/Inspector.h" | ||||
| #include "Project/ProjectInfo.h" | ||||
| #include "Runtime/RuntimeControls.h" | ||||
| #include "AssetManagement/uuid.h" | ||||
| #include "Project/Settings.h" | ||||
| #include "Console.h" | ||||
|  | ||||
| @ -26,21 +27,19 @@ public: | ||||
|         std::string path = (std::filesystem::current_path()).string(); | ||||
|         project.setProjectDirectory(path); | ||||
|  | ||||
|         AssetManager::Init(); | ||||
|         AssetManager::setAssetPath(project.GetProjectDirectory()); | ||||
|         AssetManager::BuildAssetView(); | ||||
|  | ||||
|         LoadLastOrEmptyProject(); | ||||
|  | ||||
|         ProjectInfo projectInfo(project); | ||||
|         Viewport sceneview = Viewport(scene); | ||||
|         //ProjectInfo projectInfo(project); | ||||
|         RuntimeControls rc = RuntimeControls(); | ||||
|  | ||||
|         Viewport sceneview = Viewport(scene); | ||||
|         SceneExplorer explorer(Selected, scene); | ||||
|         Inspector inspector = Inspector(Selected); | ||||
|         Settings settings = Settings(); | ||||
|        // AssetFinder assetsView = AssetFinder(); | ||||
|         Console console = Console(); | ||||
|         //Settings settings = Settings(); | ||||
|         AssetFinder assetsView = AssetFinder(); | ||||
|         //Console console = Console(); | ||||
|  | ||||
|          | ||||
|         Selected = YoggieEngine::Entity((entt::entity) -1, &scene); | ||||
|  | ||||
|         double previous = glfwGetTime(); | ||||
| @ -77,16 +76,18 @@ public: | ||||
|  | ||||
|             } | ||||
|            | ||||
|             projectInfo.Update(); | ||||
|             //projectInfo.Update(); | ||||
|             sceneview.Update(); | ||||
|             rc.Update(); | ||||
|             explorer.Update(); | ||||
|             settings.Update(); | ||||
|             //settings.Update(); | ||||
|             inspector.Update(); | ||||
|             console.Update(); | ||||
|             //console.Update(); | ||||
|              | ||||
|             assetsView.Update(); | ||||
|  | ||||
|             ImGui::ShowDemoWindow(); | ||||
|             ImGui::ShowMetricsWindow(); | ||||
|             //ImGui::ShowMetricsWindow(); | ||||
|  | ||||
|              | ||||
|             GuiEnd(); | ||||
|  | ||||
| @ -71,8 +71,8 @@ project "YoggieEngine" | ||||
|  | ||||
|   files { | ||||
|  | ||||
|     "./src/**.cpp", | ||||
|     "./src/**.h" | ||||
|     "src/**.cpp", | ||||
|     "src/**.h" | ||||
|   } | ||||
|  | ||||
|   prebuildcommands  | ||||
|  | ||||
| @ -59,9 +59,12 @@ namespace YoggieEngine { | ||||
| 		ImGui::NewFrame(); | ||||
| 		ImGuizmo::BeginFrame(); | ||||
| 		ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); | ||||
| 		 | ||||
| 	 | ||||
| 	} | ||||
|  | ||||
| 	void Application::GuiEnd() { | ||||
| 	 | ||||
| 		ImGui::EndFrame(); | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -1,102 +0,0 @@ | ||||
| #include <YoggieEngine.h> | ||||
| #include "ModelImporter.h" | ||||
|  | ||||
| namespace YoggieEngine { | ||||
|  | ||||
|     SceneObject* ModelImporter::Import(const std::string path) | ||||
|     { | ||||
|         SceneObject* root = new SceneObject(std::string(path), nullptr); | ||||
|  | ||||
|         Assimp::Importer importer; | ||||
|         const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs); | ||||
|  | ||||
|         aiNode* currentNode = scene->mRootNode; | ||||
|  | ||||
|         std::vector<Mesh> meshes = processNode(currentNode, scene); | ||||
|  | ||||
|         std::cout << "[DEBUG]: Loaded " << meshes.size() << " meshes!" << std::endl; | ||||
|  | ||||
|         // create a renderable (per mesh ?? )  | ||||
|         root->renderable = new Renderable(); | ||||
|         root->renderable->mesh = new Mesh(meshes[0]); | ||||
|  | ||||
|         return root; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     std::vector<Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) | ||||
|     { | ||||
|  | ||||
|         std::vector<Mesh> meshes; | ||||
|  | ||||
|         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; | ||||
|     } | ||||
|  | ||||
|     Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) { | ||||
|         std::vector<unsigned int> indices; | ||||
|         std::vector<Vertex> vertices; | ||||
|  | ||||
|         ProcessVertices(mesh, vertices); | ||||
|  | ||||
|         ProcessIndices(mesh, indices); | ||||
|  | ||||
|         Mesh result; | ||||
|         result.vertices = vertices; | ||||
|         result.elements = indices; | ||||
|  | ||||
|  | ||||
|         return result; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     void ProcessVertices(aiMesh* mesh, std::vector<Vertex>& out_vertices) { | ||||
|         // Process vertices | ||||
|         for (unsigned int i = 0; i < mesh->mNumVertices; i++) { | ||||
|             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) { | ||||
|         // Process 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]); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "../Graphics/Primitives/Mesh.h" | ||||
| #include <assimp/Importer.hpp> | ||||
| #include <assimp/scene.h> | ||||
| #include <assimp/postprocess.h>  | ||||
| #include <string> | ||||
| #include "../Scene/TransformTree/SceneNodeTypes.h" | ||||
|  | ||||
| namespace YoggieEngine { | ||||
| 	void ProcessVertices(aiMesh* mesh, std::vector<Vertex>& out_vertices); | ||||
| 	void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices); | ||||
|  | ||||
| 	class ModelImporter { | ||||
|  | ||||
| 	public: | ||||
|  | ||||
| 		SceneObject* Import(const std::string path); | ||||
|  | ||||
|  | ||||
| 	private: | ||||
|  | ||||
| 		static Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene); | ||||
| 		static std::vector<Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene); | ||||
|  | ||||
|  | ||||
|  | ||||
| 	}; | ||||
| } | ||||
| @ -27,7 +27,7 @@ namespace YoggieEngine { | ||||
|  | ||||
| 		} | ||||
| 		else { | ||||
| 			spdlog::error("Failed to load image (%s)", texturePath); | ||||
| 			spdlog::error("Failed to load image ({0})", texturePath); | ||||
| 		} | ||||
| 		stbi_image_free(data); | ||||
|  | ||||
|  | ||||
| @ -187,6 +187,9 @@ void SubmitVegetationDemo() { | ||||
| } | ||||
|  | ||||
| void Renderer::Submit( Render3DComponent& renderComponent, TransformComponent& transform) { | ||||
| 	if (renderComponent.mesh.elements.empty()) | ||||
| 		return; | ||||
|  | ||||
| 	if (renderComponent.VAO == 0 || renderComponent.IBO == 0)  | ||||
| 	{ | ||||
| 		if (renderComponent.VAO != 0) | ||||
| @ -435,17 +438,6 @@ void Renderer::Render(Scene& scene) | ||||
| 	BlendingPass(); | ||||
|  | ||||
| 	//PostProcessing(); | ||||
|  | ||||
|  | ||||
| 	//  Lighting pass  | ||||
| 	/* | ||||
| 	auto lights = scene.getReg().view<LightComponent>(); | ||||
| 		lights.each([&](auto entity, LightComponent& light) { | ||||
| 		  	renderComponent.shader.setUniformVec3("lighting.color", light.Color); | ||||
| 			renderComponent.shader.setUniformFloat("lighting.strength", light.Strength); | ||||
| 		}); | ||||
| 	 | ||||
| 	*/ 	 | ||||
| 	 | ||||
| 	commands.clear(); | ||||
| 	glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||||
|  | ||||
| @ -1,10 +0,0 @@ | ||||
| #include <YoggieEngine.h> | ||||
| #include "Node.h" | ||||
|  | ||||
| namespace YoggieEngine { | ||||
| 	Node::Node(const std::string& name) | ||||
| 		: name(name), parent(nullptr), children(std::vector<Node*>()) {} | ||||
|  | ||||
| 	Group::Group(const std::string& name) | ||||
| 		: Node(name) {} | ||||
| } | ||||
| @ -1,22 +0,0 @@ | ||||
| #pragma once | ||||
| namespace YoggieEngine { | ||||
| 	class Node { | ||||
| 	public: | ||||
| 		Node(const std::string& name); | ||||
| 		std::string name; | ||||
| 		Node* parent; | ||||
| 		std::vector<Node*> children; | ||||
|  | ||||
| 		void addChild(Node& node); | ||||
|  | ||||
| 	}; | ||||
|  | ||||
|  | ||||
|  | ||||
| 	class Group : public Node { | ||||
| 	public: | ||||
| 		Group(const std::string& name); | ||||
|  | ||||
| 	}; | ||||
|  | ||||
| } | ||||
| @ -1,14 +0,0 @@ | ||||
| #include <YoggieEngine.h> | ||||
| #include "SceneNodeTypes.h" | ||||
| namespace YoggieEngine { | ||||
| 	SceneCamera::SceneCamera() | ||||
| 		: Group(std::string("Camera")), camera(Camera(glm::vec3(0.0f), glm::vec3(0.0f), 0)) | ||||
| 	{} | ||||
|  | ||||
| 	SceneObject::SceneObject(std::string name, Renderable* visual) | ||||
| 		: Group(name), renderable(visual) | ||||
| 	{} | ||||
|  | ||||
| 	SceneObject::~SceneObject() | ||||
| 	{} | ||||
| } | ||||
| @ -1,21 +0,0 @@ | ||||
| #pragma once | ||||
| #include "../../Graphics/Renderable.h" | ||||
| #include "Node.h" | ||||
|  | ||||
| namespace YoggieEngine { | ||||
| 	class SceneCamera : public Group | ||||
| 	{ | ||||
| 	public: | ||||
| 		Camera& camera; | ||||
| 		SceneCamera(); | ||||
| 	}; | ||||
|  | ||||
|  | ||||
| 	class SceneObject : public Group | ||||
| 	{ | ||||
| 	public: | ||||
| 		SceneObject(std::string name, Renderable* visual); | ||||
| 		~SceneObject(); | ||||
| 		Renderable* renderable; | ||||
| 	}; | ||||
| } | ||||
| @ -25,7 +25,7 @@ void main() | ||||
|     float Specular = texture(gColorSpec, TexCoords).a; | ||||
|  | ||||
|     // calculate lighting as usual | ||||
|     vec3 lighting = Albedo * 0.1; // Hard-coded ambient light | ||||
|     vec3 lighting = Albedo * 0.0; // Hard-coded ambient light | ||||
|     vec3 viewDir = normalize(viewPos - FragPos); | ||||
|     for( int i = 0; i < NR_LIGHTS; ++i) | ||||
|     { | ||||
|  | ||||
| @ -40,8 +40,8 @@ group("Other") | ||||
|  | ||||
|  | ||||
| group("Libraries") | ||||
|   include('../ImGui') | ||||
|   include("../ImGuizmo") | ||||
|   include("../yaml-cpp") | ||||
|   include('ImGui') | ||||
|   include("ImGuizmo") | ||||
|   include("yaml-cpp") | ||||
|    | ||||
|   | ||||
|  | ||||
		Reference in New Issue
	
	Block a user