From 34b01ecff265d71c86baced08fc70d959cfdb4c4 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:27:23 +0000 Subject: [PATCH 01/33] Implement New Model Format Writer --- .../ERS_ModelWriter/ERS_ModelWriter.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp b/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp index 470287b90f..0408079cb1 100644 --- a/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp +++ b/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp @@ -268,7 +268,7 @@ std::string ERS_CLASS_ModelWriter::GenerateModelMetadata(ERS_STRUCT_ModelWriterD MetadataEmitter<Log("Saving Mesh-Texture Relationship Information To ERS Metadata Header", 4); + for (unsigned int i = 0; i < Data.Model->Meshes.size(); i++) { + MetadataEmitter<Meshes[i].Textures_.size(); x++) { + MetadataEmitter<Meshes[i].Textures_[x]->Path; + MetadataEmitter<Meshes[i].Textures_[x]->Type; + + MetadataEmitter<TotalVertices_; From 4a87050dba0332a9344dec6ccb0fceda98864216 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:34:36 +0000 Subject: [PATCH 02/33] Implement New Model Format Writer --- Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp b/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp index 0408079cb1..e9f9ac721f 100644 --- a/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp +++ b/Source/Core/Writers/ERS_ModelWriter/ERS_ModelWriter.cpp @@ -312,11 +312,11 @@ std::string ERS_CLASS_ModelWriter::GenerateModelMetadata(ERS_STRUCT_ModelWriterD Logger_->Log("Saving Mesh-Texture Relationship Information To ERS Metadata Header", 4); for (unsigned int i = 0; i < Data.Model->Meshes.size(); i++) { MetadataEmitter<Meshes[i].Textures_.size(); x++) { + for (unsigned int x = 0; x < Data.Model->Meshes[i].Loader_RequestedTextureInformation_.size(); x++) { MetadataEmitter<Meshes[i].Textures_[x]->Path; - MetadataEmitter<Meshes[i].Textures_[x]->Type; + MetadataEmitter<Meshes[i].Loader_RequestedTextureInformation_[x].second; + MetadataEmitter<Meshes[i].Loader_RequestedTextureInformation_[x].first; MetadataEmitter< Date: Mon, 12 Sep 2022 05:42:15 +0000 Subject: [PATCH 03/33] Implement New Model Format Writer --- .../ERS_CLASS_ExternalModelLoader.cpp | 47 +++++++++---------- .../ERS_CLASS_ExternalModelLoader.h | 4 +- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index ee0bfac51b..1d81684ffb 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -316,39 +316,38 @@ void ERS_CLASS_ExternalModelLoader::ProcessNode(ERS_STRUCT_ModelWriterData &Data } -void ERS_CLASS_ExternalModelLoader::HandleMeshTextures(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial* Material, std::string ModelDirectory) { +void ERS_CLASS_ExternalModelLoader::HandleMeshTextures(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial* Material, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh) { SystemUtils_->Logger_->Log("Identifying Mesh Textures", 3); - AddTexture(Data, Model, Material, aiTextureType_AMBIENT, "texture_ambient", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_AMBIENT_OCCLUSION, "texture_ambient_occlusion", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_BASE_COLOR, "texture_base_color", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_DIFFUSE, "texture_diffuse", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_DIFFUSE_ROUGHNESS, "texture_diffuse_roughness", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_DISPLACEMENT, "texture_displacement", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_EMISSION_COLOR, "texture_emission_color", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_EMISSIVE, "texture_emissive", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_HEIGHT, "texture_height", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_LIGHTMAP, "texture_lightmap", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_METALNESS, "texture_metalness", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_NORMAL_CAMERA, "texture_normal_camera", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_NORMALS, "texture_normals", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_OPACITY, "texture_opacity", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_REFLECTION, "texture_reflection", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_SHININESS, "texture_shininess", ModelDirectory); - AddTexture(Data, Model, Material, aiTextureType_SPECULAR, "texture_specular", ModelDirectory); + AddTexture(Data, Model, Material, aiTextureType_AMBIENT, "texture_ambient", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_AMBIENT_OCCLUSION, "texture_ambient_occlusion", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_BASE_COLOR, "texture_base_color", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_DIFFUSE, "texture_diffuse", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_DIFFUSE_ROUGHNESS, "texture_diffuse_roughness", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_DISPLACEMENT, "texture_displacement", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_EMISSION_COLOR, "texture_emission_color", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_EMISSIVE, "texture_emissive", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_HEIGHT, "texture_height", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_LIGHTMAP, "texture_lightmap", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_METALNESS, "texture_metalness", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_NORMAL_CAMERA, "texture_normal_camera", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_NORMALS, "texture_normals", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_OPACITY, "texture_opacity", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_REFLECTION, "texture_reflection", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_SHININESS, "texture_shininess", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_SPECULAR, "texture_specular", ModelDirectory, TargetMesh); SystemUtils_->Logger_->Log("Finshed Mesh Texture Identification", 4); } ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMesh *Mesh, const aiScene *Scene, std::string ModelDirectory) { - // Process Materials - aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; - HandleMeshTextures(Data, Model, Material, ModelDirectory); - - // Create Data Holders ERS_STRUCT_Mesh OutputMesh; + // Process Materials + aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; + HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); + // Iterate Through Meshes' Vertices for (unsigned int i = 0; i < Mesh->mNumVertices; i++) { @@ -415,7 +414,7 @@ ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWrite return OutputMesh; } -void ERS_CLASS_ExternalModelLoader::AddTexture(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial *Mat, aiTextureType Type, std::string TypeName, std::string ModelDirectory) { +void ERS_CLASS_ExternalModelLoader::AddTexture(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial *Mat, aiTextureType Type, std::string TypeName, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh) { for (unsigned int i=0; i< Mat->GetTextureCount(Type); i++) { diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h index 44c2352f4c..c2e3b776e5 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h @@ -86,7 +86,7 @@ class ERS_CLASS_ExternalModelLoader { * @param Type * @param TypeName */ - void AddTexture(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial *Mat, aiTextureType Type, std::string TypeName, std::string ModelDirectory); + void AddTexture(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial *Mat, aiTextureType Type, std::string TypeName, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh); /** @@ -119,7 +119,7 @@ class ERS_CLASS_ExternalModelLoader { * @param Material * @param ModelDirectory */ - void HandleMeshTextures(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial* Material, std::string ModelDirectory); + void HandleMeshTextures(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial* Material, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh); /** * @brief Finds and loads all the relevant textures into memory. From 1437dee18a78ea6ca5e2ab7e47515beae5e1c337 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:44:21 +0000 Subject: [PATCH 04/33] Implement New Model Format Writer --- .../ERS_CLASS_ExternalModelLoader.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index 1d81684ffb..1015c8d646 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -429,6 +429,7 @@ void ERS_CLASS_ExternalModelLoader::AddTexture(ERS_STRUCT_ModelWriterData &Data, if (std::find(Data.TextureList.begin(), Data.TextureList.end(), FilePath) == Data.TextureList.end()) { Data.TextureList.push_back(FilePath); Data.TextureNames.push_back(Str.C_Str()); + TargetMesh->Loader_RequestedTextureInformation_.push_back(std::make_pair(Str.C_Str(), FilePath)); } } From a21979b72648f5fdeb5c1b7c3a1baf55c61a066f Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:47:21 +0000 Subject: [PATCH 05/33] Implement New Model Format Writer --- .../ERS_CLASS_ExternalModelLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index 1015c8d646..5adecfa020 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -429,7 +429,7 @@ void ERS_CLASS_ExternalModelLoader::AddTexture(ERS_STRUCT_ModelWriterData &Data, if (std::find(Data.TextureList.begin(), Data.TextureList.end(), FilePath) == Data.TextureList.end()) { Data.TextureList.push_back(FilePath); Data.TextureNames.push_back(Str.C_Str()); - TargetMesh->Loader_RequestedTextureInformation_.push_back(std::make_pair(Str.C_Str(), FilePath)); + TargetMesh->Loader_RequestedTextureInformation_.push_back(std::make_pair(TypeName, Str.C_Str())); } } From 91619d5f28191d693b08742b340a1e454b64bbd5 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:52:17 +0000 Subject: [PATCH 06/33] Implement New Model Format Writer --- .../ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp index 12e08a22a5..d115ab1074 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp @@ -576,25 +576,25 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi void ERS_CLASS_ModelLoader::IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh) { std::vector> TextureTypes; - TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT, "texture_ambient")); + TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT, "texture_ambient")); TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT_OCCLUSION, "texture_ambient_occlusion")); - TextureTypes.push_back(std::make_pair(aiTextureType_BASE_COLOR, "texture_base_color")); - TextureTypes.push_back(std::make_pair(aiTextureType_DIFFUSE, "texture_diffuse")); + TextureTypes.push_back(std::make_pair(aiTextureType_BASE_COLOR, "texture_base_color")); + TextureTypes.push_back(std::make_pair(aiTextureType_DIFFUSE, "texture_diffuse")); TextureTypes.push_back(std::make_pair(aiTextureType_DIFFUSE_ROUGHNESS, "texture_diffuse_roughness")); - TextureTypes.push_back(std::make_pair(aiTextureType_DISPLACEMENT, "texture_displacement")); - TextureTypes.push_back(std::make_pair(aiTextureType_EMISSION_COLOR, "texture_emission_color")); - TextureTypes.push_back(std::make_pair(aiTextureType_EMISSIVE, "texture_emissive")); - TextureTypes.push_back(std::make_pair(aiTextureType_HEIGHT, "texture_height")); - TextureTypes.push_back(std::make_pair(aiTextureType_LIGHTMAP, "texture_lightmap")); - TextureTypes.push_back(std::make_pair(aiTextureType_METALNESS, "texture_metalness")); - TextureTypes.push_back(std::make_pair(aiTextureType_NONE, "texture_none")); - TextureTypes.push_back(std::make_pair(aiTextureType_NORMAL_CAMERA, "texture_normal_camera")); - TextureTypes.push_back(std::make_pair(aiTextureType_NORMALS, "texture_normals")); - TextureTypes.push_back(std::make_pair(aiTextureType_OPACITY, "texture_opacity")); - TextureTypes.push_back(std::make_pair(aiTextureType_REFLECTION, "texture_reflection")); - TextureTypes.push_back(std::make_pair(aiTextureType_SHININESS, "texture_shininess")); - TextureTypes.push_back(std::make_pair(aiTextureType_SPECULAR, "texture_specular")); - TextureTypes.push_back(std::make_pair(aiTextureType_UNKNOWN, "texture_unknown")); + TextureTypes.push_back(std::make_pair(aiTextureType_DISPLACEMENT, "texture_displacement")); + TextureTypes.push_back(std::make_pair(aiTextureType_EMISSION_COLOR, "texture_emission_color")); + TextureTypes.push_back(std::make_pair(aiTextureType_EMISSIVE, "texture_emissive")); + TextureTypes.push_back(std::make_pair(aiTextureType_HEIGHT, "texture_height")); + TextureTypes.push_back(std::make_pair(aiTextureType_LIGHTMAP, "texture_lightmap")); + TextureTypes.push_back(std::make_pair(aiTextureType_METALNESS, "texture_metalness")); + TextureTypes.push_back(std::make_pair(aiTextureType_NONE, "texture_none")); + TextureTypes.push_back(std::make_pair(aiTextureType_NORMAL_CAMERA, "texture_normal_camera")); + TextureTypes.push_back(std::make_pair(aiTextureType_NORMALS, "texture_normals")); + TextureTypes.push_back(std::make_pair(aiTextureType_OPACITY, "texture_opacity")); + TextureTypes.push_back(std::make_pair(aiTextureType_REFLECTION, "texture_reflection")); + TextureTypes.push_back(std::make_pair(aiTextureType_SHININESS, "texture_shininess")); + TextureTypes.push_back(std::make_pair(aiTextureType_SPECULAR, "texture_specular")); + TextureTypes.push_back(std::make_pair(aiTextureType_UNKNOWN, "texture_unknown")); // Iterate Over All Texture Types for (unsigned int TextureTypeIndex = 0; TextureTypeIndex < TextureTypes.size(); TextureTypeIndex++) { From 0a6b78afd40a98c2611357bec7c206c0755eacdf Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:53:14 +0000 Subject: [PATCH 07/33] Implement New Model Format Loader --- .../ERS_FUNCTION_ModelMetadataDecoderManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp index ba0a681eac..32a0a60ae2 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp @@ -24,7 +24,7 @@ bool ERS_FUNCTION_DecodeModelMetadata(YAML::Node Metadata, ERS_STRUCT_Model* Mod Status = ERS_FUNCTION_DecodeModelMetadataV001(Metadata, Model, SystemUtils, AssetID, LogEnable); } else { // Failed To Decode Version - SystemUtils->Logger_->Log("Failed To Decode Metadata Version, Aborting Load", 8); + SystemUtils->Logger_->Log("Unsupported Format Version, Aborting Load", 8); return false; } From d383d06c2e5b0f4aac8a425aad80d051a2590ca7 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:55:35 +0000 Subject: [PATCH 08/33] Implement New Model Format Loader --- ...RS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp | 139 ++++++++++++++++++ .../ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h | 35 +++++ 2 files changed, 174 insertions(+) create mode 100644 Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp create mode 100644 Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp new file mode 100644 index 0000000000..5063652851 --- /dev/null +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp @@ -0,0 +1,139 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +bool ERS_FUNCTION_DecodeModelMetadataV002(YAML::Node Metadata, ERS_STRUCT_Model* Model, ERS_STRUCT_SystemUtils* SystemUtils, long AssetID, bool LogEnable) { + + + // Setup Processing Variables + bool DecodeStatus = true; + + // Attempt To Decode, Handle Errors + try { + + SystemUtils->Logger_->Log("Decoding Model Metadata", 3, LogEnable); + + if (Model->Name == "Loading...") { + if (Metadata["Name"]) { + std::string Name = Metadata["Name"].as(); + Model->Name = Name.substr(Name.find_last_of("/") + 1, Name.length()-1); + } else { + Model->Name = "_Error_"; + SystemUtils->Logger_->Log(std::string("Error Loading Name From Model Metadata '") + std::to_string(AssetID) + "'", 7); + DecodeStatus = false; + } + } + + if (Metadata["ModelID"]) { + Model->ModelDataID = Metadata["ModelID"].as(); + } else { + Model->ModelDataID = -1; + SystemUtils->Logger_->Log(std::string("Error Loading 3DAssetID From Model Metadata '") + std::to_string(AssetID) + "'", 7); + DecodeStatus = false; + } + + if (Metadata["Vertices"]) { + Model->TotalVertices_ = Metadata["Vertices"].as(); + } else { + Model->TotalVertices_ = -1; + SystemUtils->Logger_->Log(std::string("Error Loading Vertices Parameter From Model Metadata '") + std::to_string(AssetID) + "'", 7); + DecodeStatus = false; + } + + if (Metadata["Indices"]) { + Model->TotalIndices_ = Metadata["Indices"].as(); + } else { + Model->TotalIndices_ = -1; + SystemUtils->Logger_->Log(std::string("Error Loading Indices Parameter From Model Metadata '") + std::to_string(AssetID) + "'", 7); + DecodeStatus = false; + } + + if (Metadata["BoundingBoxX"] && Metadata["BoundingBoxY"] && Metadata["BoundingBoxZ"]) { + double BoxX = Metadata["BoundingBoxX"].as(); + double BoxY = Metadata["BoundingBoxY"].as(); + double BoxZ = Metadata["BoundingBoxZ"].as(); + Model->BoxScale_ = glm::vec3(BoxX, BoxY, BoxZ); + } else { + Model->BoxScale_ = glm::vec3(1.0f); + SystemUtils->Logger_->Log(std::string("Error Loading Bounding Box Size Parameter From Model Metadata '") + std::to_string(AssetID) + "'", 7); + DecodeStatus = false; + } + + if (Metadata["OffsetX"] && Metadata["OffsetY"] && Metadata["OffsetZ"]) { + double OffsetX = Metadata["OffsetX"].as(); + double OffsetY = Metadata["OffsetY"].as(); + double OffsetZ = Metadata["OffsetZ"].as(); + Model->BoxOffset_ = glm::vec3(OffsetX, OffsetY, OffsetZ); + } else { + Model->BoxOffset_ = glm::vec3(0.0f); + SystemUtils->Logger_->Log(std::string("Error Loading Origin Offset Parameter From Model Metadata '") + std::to_string(AssetID) + "'", 7); + DecodeStatus = false; + } + + if (Metadata["Textures"]) { + YAML::Node TexturePathNode = Metadata["Textures"]; + for (YAML::const_iterator it=TexturePathNode.begin(); it!=TexturePathNode.end(); ++it) { + + // Setup Texture Struct + ERS_STRUCT_Texture Texture; + Texture.Path = it->first.as(); + SystemUtils->Logger_->Log(std::string("Found Texture '") + Texture.Path + "'", 3, LogEnable); + + // Add All Levels To This Texture + YAML::Node TextureLevels = it->second; + for (YAML::const_iterator LevelIterator = TextureLevels.begin(); LevelIterator != TextureLevels.end(); ++LevelIterator) { + + YAML::Node LevelInfo = LevelIterator->second; + ERS_STRUCT_TextureLevel TexLevel; + TexLevel.LevelTextureAssetID = LevelInfo["TextureLevelAssetID"].as(); + TexLevel.LevelTextureOpenGLID = 0; + TexLevel.LevelMemorySizeBytes = LevelInfo["TextureLevelMemorySizeBytes"].as(); + TexLevel.LevelResolution = std::make_pair(LevelInfo["TextureLevelResolutionX"].as(), LevelInfo["TextureLevelResolutionY"].as()); + TexLevel.LevelChannel = LevelInfo["TextureLevelNumberChannels"].as(); + TexLevel.LevelBitmap = nullptr; + TexLevel.LevelLoadedInRAM = false; + TexLevel.LevelLoadedInVRAM = false; + TexLevel.Level = LevelIterator->first.as(); + Texture.TextureLevels.push_back(TexLevel); + + SystemUtils->Logger_->Log(std::string("Detected Texture Level '") + std::to_string(LevelIterator->first.as()) + + "', Resolution '" + std::to_string(LevelInfo["TextureLevelResolutionX"].as()) + + "x" + std::to_string(LevelInfo["TextureLevelResolutionY"].as()) + + "'", 1, LogEnable); + + } + Model->Textures_.push_back(Texture); + } + + if (Model->Textures_.size() > 0) { + Model->MaxTextureLevel_ = Model->Textures_[0].TextureLevels.size() - 1; + } else { + Model->MaxTextureLevel_ = -1; + } + + + } else { + SystemUtils->Logger_->Log(std::string("Error Loading Texture Manifest From Model Metadata'") + std::to_string(AssetID) + "'", 7); + DecodeStatus = false; + } + + SystemUtils->Logger_->Log("Finished Decoding Model Metadata", 3, LogEnable); + return DecodeStatus; + + } catch(YAML::BadSubscript&) { + SystemUtils->Logger_->Log(std::string(std::string("Error Loading Model '") + std::to_string(AssetID) + std::string("', Asset Metadata Corrupt")).c_str(), 9); + return false; + + } catch(YAML::TypedBadConversion&) { + SystemUtils->Logger_->Log(std::string(std::string("Error Loading Model '") + std::to_string(AssetID) + std::string("', ModelID/TextureIDs Corrupt")).c_str(), 9); + return false; + + } catch(YAML::TypedBadConversion&) { + SystemUtils->Logger_->Log(std::string(std::string("Error Loading Model '") + std::to_string(AssetID) + std::string("', Model Name Corrupt")).c_str(), 9); + return false; + } + +} \ No newline at end of file diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h new file mode 100644 index 0000000000..4fa25dad01 --- /dev/null +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h @@ -0,0 +1,35 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include + +#include +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include + + +/** + * @brief Decodes model metadata from the yaml system. + * Handles metadata for model with version 0 - or unspecified. + * + * @param Metadata + * @param Model + * @param SystemUtils + * @param AssetID + * @return true + * @return false + */ +bool ERS_FUNCTION_DecodeModelMetadataV002(YAML::Node Metadata, ERS_STRUCT_Model* Model, ERS_STRUCT_SystemUtils* SystemUtils, long AssetID, bool LogEnable = true); \ No newline at end of file From 34b3308b1881675e07ba1c3d02ac03fc718f290b Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:56:01 +0000 Subject: [PATCH 09/33] Implement New Model Format Loader --- Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt b/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt index 32112af4df..048cc3e49e 100644 --- a/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt +++ b/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(ERS_ModelLoader "ERS_CLASS_AssetStreamingSystemResourceMonitor.cpp" "ERS_FUNCTION_ModelMetadataDecoderV0.0.0.cpp" "ERS_FUNCTION_ModelMetadataDecoderV0.0.1.cpp" + "ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp" "ERS_FUNCTION_ModelMetadataDecoderManager.cpp" # Add Header Files (.h) @@ -22,6 +23,7 @@ add_library(ERS_ModelLoader "ERS_CLASS_AssetStreamingSystemResourceMonitor.h" "ERS_FUNCTION_ModelMetadataDecoderV0.0.0.h" "ERS_FUNCTION_ModelMetadataDecoderV0.0.1.h" + "ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h" "ERS_FUNCTION_ModelMetadataDecoderManager.h" From ef5bd9399e998b975431966d641b31c2634907da Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 05:57:43 +0000 Subject: [PATCH 10/33] Implement New Model Format Loader --- .../ERS_FUNCTION_ModelMetadataDecoderManager.cpp | 3 +++ .../ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h | 1 + 2 files changed, 4 insertions(+) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp index 32a0a60ae2..95459e1805 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp @@ -22,6 +22,9 @@ bool ERS_FUNCTION_DecodeModelMetadata(YAML::Node Metadata, ERS_STRUCT_Model* Mod } else if (FormatVersion == "0.0.1") { SystemUtils->Logger_->Log("Determined Model Metadata Version To Be '0.0.1', Attempting To Decode Model Metadata", 3, LogEnable); Status = ERS_FUNCTION_DecodeModelMetadataV001(Metadata, Model, SystemUtils, AssetID, LogEnable); + } else if (FormatVersion == "0.0.2") { + SystemUtils->Logger_->Log("Determined Model Metadata Version To Be '0.0.2', Attempting To Decode Model Metadata", 3, LogEnable); + Status = ERS_FUNCTION_DecodeModelMetadataV002(Metadata, Model, SystemUtils, AssetID, LogEnable); } else { // Failed To Decode Version SystemUtils->Logger_->Log("Unsupported Format Version, Aborting Load", 8); diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h index 79f09f179b..dd4587613e 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h @@ -20,6 +20,7 @@ #include #include +#include /** From bdda875d5cfb73dcacb65ad9fe868e2695bee1cb Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:07:49 +0000 Subject: [PATCH 11/33] Implement New Model Format Loader --- ...RS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp index 5063652851..a0eea1a9a4 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp @@ -120,6 +120,27 @@ bool ERS_FUNCTION_DecodeModelMetadataV002(YAML::Node Metadata, ERS_STRUCT_Model* DecodeStatus = false; } + + if (Metadata["Meshes"]) { + YAML::Node MeshNode = Metadata["Meshes"]; + for (YAML::const_iterator it=MeshNode.begin(); it!=MeshNode.end(); ++it) { + + // Setup Mesh Struct + ERS_STRUCT_Mesh Mesh; + + // Add All Levels To This Texture + YAML::Node MeshTextures = it->second; + for (YAML::const_iterator LevelIterator = MeshTextures.begin(); LevelIterator != MeshTextures.end(); ++LevelIterator) { + + YAML::Node MeshTexture = LevelIterator->second; + Mesh.Loader_RequestedTextureInformation_.push_back(std::make_pair(MeshTexture["Identifier"].as(), MeshTexture["Type"].as())); + + + } + Model->Meshes.push_back(Mesh); + } + } + SystemUtils->Logger_->Log("Finished Decoding Model Metadata", 3, LogEnable); return DecodeStatus; From d15729411ae89c3b6987c2acf69515a717089bee Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:10:30 +0000 Subject: [PATCH 12/33] Implement New Model Format Loader --- .../ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp index a0eea1a9a4..4d3aafdab0 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp @@ -133,7 +133,7 @@ bool ERS_FUNCTION_DecodeModelMetadataV002(YAML::Node Metadata, ERS_STRUCT_Model* for (YAML::const_iterator LevelIterator = MeshTextures.begin(); LevelIterator != MeshTextures.end(); ++LevelIterator) { YAML::Node MeshTexture = LevelIterator->second; - Mesh.Loader_RequestedTextureInformation_.push_back(std::make_pair(MeshTexture["Identifier"].as(), MeshTexture["Type"].as())); + Mesh.Loader_RequestedTextureInformation_.push_back(std::make_pair(MeshTexture["Type"].as(), MeshTexture["Identifier"].as())); } From 285c076728e6ffa454af141a834254aa79034ebd Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:19:03 +0000 Subject: [PATCH 13/33] Implement New Model Format Loader --- Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp | 4 ++++ Source/Core/Structures/ERS_STRUCT_Model/ERS_STRUCT_Model.h | 1 + 2 files changed, 5 insertions(+) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp index d115ab1074..9efe9379c8 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp @@ -495,6 +495,8 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi // Create Data Holders ERS_STRUCT_Mesh OutputMesh; + OutputMesh = Model->Meshes[Model->NumMeshes_]; + OutputMesh.Vertices.reserve(PreallocVertSize); @@ -569,6 +571,8 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi // Return Populated Mesh + Model->Meshes[Model->NumMeshes] = OutputMesh; + Model->NumMeshes_++; return OutputMesh; } diff --git a/Source/Core/Structures/ERS_STRUCT_Model/ERS_STRUCT_Model.h b/Source/Core/Structures/ERS_STRUCT_Model/ERS_STRUCT_Model.h index 59d9f83a42..d52c90cf85 100644 --- a/Source/Core/Structures/ERS_STRUCT_Model/ERS_STRUCT_Model.h +++ b/Source/Core/Structures/ERS_STRUCT_Model/ERS_STRUCT_Model.h @@ -35,6 +35,7 @@ struct ERS_STRUCT_Model { std::string Name = "Name Not Assigned"; long ShaderOverrideIndex_ = -1; /** Date: Mon, 12 Sep 2022 06:19:44 +0000 Subject: [PATCH 14/33] Implement New Model Format Loader --- .../ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp index 9efe9379c8..104f3e1d4b 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp @@ -471,15 +471,13 @@ void ERS_CLASS_ModelLoader::ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, c // Process Meshes In Current Node for (unsigned int i = 0; i < Node->mNumMeshes; i++) { aiMesh* Mesh = Scene->mMeshes[Node->mMeshes[i]]; - Model->Meshes.push_back( - ProcessMesh( - Model, - (unsigned long)Mesh->mNumVertices, - (unsigned long)Mesh->mNumFaces*3, - Mesh, - Scene - ) - ); + ProcessMesh( + Model, + (unsigned long)Mesh->mNumVertices, + (unsigned long)Mesh->mNumFaces*3, + Mesh, + Scene + ) } @@ -571,8 +569,9 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi // Return Populated Mesh - Model->Meshes[Model->NumMeshes] = OutputMesh; + Model->Meshes[Model->NumMeshes_] = OutputMesh; Model->NumMeshes_++; + return OutputMesh; } From 7f718c680a05c4204138e497cc320467b1325faf Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:21:05 +0000 Subject: [PATCH 15/33] Implement New Model Format Loader --- Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp index 104f3e1d4b..5b3676d0cf 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp @@ -477,7 +477,7 @@ void ERS_CLASS_ModelLoader::ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, c (unsigned long)Mesh->mNumFaces*3, Mesh, Scene - ) + ); } From 276dfff03dfe369bae0dc91797b09ed123cb552f Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:29:12 +0000 Subject: [PATCH 16/33] Implement New Model Format Loader --- .../Loader/ERS_ModelLoader/CMakeLists.txt | 2 + ..._FUNCTION_Legacy_PreprocessTextureInfo.cpp | 641 ++++++++++++++++++ ...RS_FUNCTION_Legacy_PreprocessTextureInfo.h | 215 ++++++ 3 files changed, 858 insertions(+) create mode 100644 Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp create mode 100644 Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h diff --git a/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt b/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt index 048cc3e49e..18f44085dd 100644 --- a/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt +++ b/Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(ERS_ModelLoader "ERS_CLASS_AssetStreamingManager.cpp" "ERS_CLASS_AsyncTextureUpdater.cpp" "ERS_CLASS_AssetStreamingSystemResourceMonitor.cpp" + "ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp" "ERS_FUNCTION_ModelMetadataDecoderV0.0.0.cpp" "ERS_FUNCTION_ModelMetadataDecoderV0.0.1.cpp" "ERS_FUNCTION_ModelMetadataDecoderV0.0.2.cpp" @@ -21,6 +22,7 @@ add_library(ERS_ModelLoader "ERS_CLASS_AssetStreamingManager.h" "ERS_CLASS_AsyncTextureUpdater.h" "ERS_CLASS_AssetStreamingSystemResourceMonitor.h" + "ERS_FUNCTION_Legacy_PreprocessTextureInfo.h" "ERS_FUNCTION_ModelMetadataDecoderV0.0.0.h" "ERS_FUNCTION_ModelMetadataDecoderV0.0.1.h" "ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h" diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp new file mode 100644 index 0000000000..5b3676d0cf --- /dev/null +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -0,0 +1,641 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + +// FIXME: +// Cleanup Doxygen, fix headers, etc. +// optionally optimize processgpu function to provide least amount of lag as possible +// Add Placeholder meshes during loading + +ERS_CLASS_ModelLoader::ERS_CLASS_ModelLoader(ERS_STRUCT_SystemUtils* SystemUtils, int MaxModelLoadingThreads) { + + SystemUtils_ = SystemUtils; + SystemUtils_->Logger_->Log("Initializing Model Loader", 5); + FreeImage_Initialise(); + + + + AssetStreamingManager_ = std::make_unique(SystemUtils_); + + + + if (MaxModelLoadingThreads == -1) { + SystemUtils_->Logger_->Log("Identifying Number Of CPU Cores", 4); + MaxModelLoadingThreads = std::thread::hardware_concurrency(); + SystemUtils_->Logger_->Log(std::string(std::string("Identified ") + std::to_string(MaxModelLoadingThreads) + std::string(" Cores")).c_str(), 4); + } + SystemUtils_->Logger_->Log(std::string(std::string("Creating ") + std::to_string(MaxModelLoadingThreads) + std::string("Model Loading Threads")).c_str(), 4); + for (int i = 0; i < MaxModelLoadingThreads; i++) { + SystemUtils_->Logger_->Log(std::string(std::string("Creating Worker Thread ") + std::to_string(i)).c_str(), 3); + WorkerThreads_.push_back(std::thread(&ERS_CLASS_ModelLoader::WorkerThread, this, i)); + } + + //SystemUtils_->Logger_->Log("Creating Reference Loading Thread", 5); + //ModelRefrenceThread_ = std::thread(&ERS_CLASS_ModelLoader::ReferenceThread, this); + + +} + +ERS_CLASS_ModelLoader::~ERS_CLASS_ModelLoader() { + + SystemUtils_->Logger_->Log("ERS_CLASS_ModelLoader Destructor Called", 6); + FreeImage_DeInitialise(); + + + + // Shutdown Threads + SystemUtils_->Logger_->Log("Sending Join Command To Worker Threads", 5); + BlockThread_.lock(); + ExitThreads_ = true; + BlockThread_.unlock(); + + SystemUtils_->Logger_->Log("Joining Worker Threads", 6); + for (int i = 0; (long)i < (long)WorkerThreads_.size(); i++) { + SystemUtils_->Logger_->Log(std::string(std::string("Joining Worker Thread ") + std::to_string(i)).c_str(), 3); + WorkerThreads_[i].join(); + } + SystemUtils_->Logger_->Log("Finished Joining Worker Threads", 6); + + + // SystemUtils_->Logger_->Log("Sending Join Command To Reference Thread", 5); + // std::lock_guard Deleteme(BlockRefThread_); + // ExitRefThread_ = true; + + // SystemUtils_->Logger_->Log("Joining Reference Loader Thread", 5); + // ModelRefrenceThread_.join(); + // SystemUtils_->Logger_->Log("Finished Joining Reference Loader Thread", 5); + + +} + +void ERS_CLASS_ModelLoader::WorkerThread(int WorkerThreadNumber) { + + std::string ThreadName = std::string("ERS_GLT-") + std::to_string(WorkerThreadNumber); + SetThreadName(ThreadName); + + bool ThreadShouldRun = true; + while (ThreadShouldRun) { + + // Acquire Check Lock + BlockThread_.lock(); + if (ExitThreads_) { + ThreadShouldRun = false; + BlockThread_.unlock(); + } else { + + // Check If Items In Work Queue + int Size = WorkItems_.size(); + if (Size > 0) { + + // Get Item, Remove From Queue, Unlock + std::shared_ptr WorkItem = WorkItems_[0]; + long WorkID = WorkIDs_[0]; + + + WorkItems_.erase(WorkItems_.begin()); + WorkIDs_.erase(WorkIDs_.begin()); + + + BlockThread_.unlock(); + + // Process Item + LoadModel(WorkID, WorkItem); + + } else { + + // No Work Items, Unlock Mutex, Sleep Thread + BlockThread_.unlock(); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + + } + } + + + } + +} + +void ERS_CLASS_ModelLoader::ProcessNewModels(ERS_STRUCT_Scene* ActiveScene) { + + // Check List Of Models + for (unsigned long i = 0; i Models.size(); i++) { + + if ( (ActiveScene->Models[i]->IsReadyForGPU) && !(ActiveScene->Models[i]->FullyReady) ) { + + SystemUtils_->Logger_->Log(std::string(std::string("Pushing Material Information To GPU For Asset: ") + std::to_string(ActiveScene->Models[i]->AssetID)).c_str(), 4); + + ProcessGPU(ActiveScene->Models[i]); + ActiveScene->Models[i]->FullyReady = true; + + } + + } + +} + +void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(std::shared_ptr Model) { + AddModelToLoadingQueue(Model->AssetID, Model); +} + +void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(long AssetID, std::shared_ptr Model) { + + // Log Addition + SystemUtils_->Logger_->Log(std::string(std::string("Adding Model '") + std::to_string(AssetID) + std::string("' To Load Queue")).c_str(), 4); + + // Add To Queue + BlockThread_.lock(); + + WorkIDs_.push_back(AssetID); + WorkItems_.push_back(Model); + + + BlockThread_.unlock(); + +} + + +void ERS_CLASS_ModelLoader::ProcessGPU(std::shared_ptr Model) { + + + + // // Push Textures To GPU RAM + // for (unsigned long i = 0; i < Model->TexturesToPushToGPU_.size(); i++) { + + // // Generate Texture + // unsigned int TextureID; + // glGenTextures(1, &TextureID); + // glBindTexture(GL_TEXTURE_2D, TextureID); + + // // Set Texture Properties + // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + + // // Convert FIBITMAP* To Raw Image Bytes + // unsigned char* RawImageData = Model->TexturesToPushToGPU_[i].ImageBytes; + + // if (RawImageData != NULL) { + // if (Model->TexturesToPushToGPU_[i].FreeImageBackend) { + // if (Model->TexturesToPushToGPU_[i].Channels == 4) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, RawImageData); + // } else if (Model->TexturesToPushToGPU_[i].Channels == 3) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_BGR, GL_UNSIGNED_BYTE, RawImageData); + // } else if (Model->TexturesToPushToGPU_[i].Channels == 2) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RG, GL_UNSIGNED_BYTE, RawImageData); + // } else if (Model->TexturesToPushToGPU_[i].Channels == 1) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RED, GL_UNSIGNED_BYTE, RawImageData); + // } else { + // SystemUtils_->Logger_->Log(std::string("Texture With ID '") + Model->TexturesToPushToGPU_[i].Path + std::string("' For Model '") + Model->Name + std::string("' Has Unsupported Number Of Channels: ") + std::to_string(Model->TexturesToPushToGPU_[i].Channels), 8); + // } + // } else { + // if (Model->TexturesToPushToGPU_[i].Channels == 4) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, RawImageData); + // } else if (Model->TexturesToPushToGPU_[i].Channels == 3) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RGB, GL_UNSIGNED_BYTE, RawImageData); + // } else if (Model->TexturesToPushToGPU_[i].Channels == 2) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RG, GL_UNSIGNED_BYTE, RawImageData); + // } else if (Model->TexturesToPushToGPU_[i].Channels == 1) { + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RED, GL_UNSIGNED_BYTE, RawImageData); + // } else { + // SystemUtils_->Logger_->Log(std::string("Texture With ID '") + Model->TexturesToPushToGPU_[i].Path + std::string("' For Model '") + Model->Name + std::string("' Has Unsupported Number Of Channels: ") + std::to_string(Model->TexturesToPushToGPU_[i].Channels), 8); + // } + // } + + // glGenerateMipmap(GL_TEXTURE_2D); + + // } else { + // SystemUtils_->Logger_->Log("Texture Failed To Load, Cannot Push To GPU", 9); + // } + + + + // // Unload Image Data + // if (Model->TexturesToPushToGPU_[i].FreeImageBackend) { + // FreeImage_Unload(Model->TexturesToPushToGPU_[i].ImageData); + // } else { + // stbi_image_free(Model->TexturesToPushToGPU_[i].ImageBytes); + // } + + // // Append To Texture Index + // Model->OpenGLTextureIDs_.push_back(TextureID); + // } + + + + // Erase List To Save Memory + //Model->TexturesToPushToGPU_.erase(Model->TexturesToPushToGPU_.begin(), Model->TexturesToPushToGPU_.end()); + Model->IsTemplateModel = true; + + + + // Collect Vertex Count Analytics + for (unsigned long i = 0; i < Model->Meshes.size(); i++) { + Model->TotalVertices_ += Model->Meshes[i].Vertices.size(); + Model->TotalIndices_ += Model->Meshes[i].Indices.size(); + } + + // Process Texture References, Setup Meshes + for (unsigned long i = 0; i < Model->Meshes.size(); i++) { + + // Set Shadow Configuration Pointers + Model->Meshes[i].CastDynamicShadows_ = &Model->CastDynamicShadows_; + Model->Meshes[i].CastStaticShadows_ = &Model->CastStaticShadows_; + Model->Meshes[i].ReceiveShadows_ = &Model->ReceiveShadows_; + + + // for (unsigned long Index = 0; Index < Model->Meshes[i].TextureReferences_.size(); Index++) { // IF TEXTURES DONT WORK, CHECK HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + // int TextureIndex = Model->Meshes[i].TextureReferences_[Index]; + + // if (TextureIndex == -1) { + // SystemUtils_->Logger_->Log("Failed To Find Corresponding Texture", 8); + // Model->Meshes[i].TextureIDs.push_back(-1); + // Model->Meshes[i].TextureColorChannels_.push_back(0); + // } else { + // Model->Meshes[i].TextureIDs.push_back(Model->OpenGLTextureIDs_[TextureIndex]); + // Model->Meshes[i].TextureColorChannels_.push_back(Model->TexturesToPushToGPU_[TextureIndex].Channels); + // } + + + // } + Model->Meshes[i].SetupMesh(); + // Perhaps save mem by erasing the vertices after pusning? (also indices) + } + + + Model->LoadingFinishTime_ = glfwGetTime(); + Model->TotalLoadingTime_ = Model->LoadingFinishTime_ - Model->LoadingStartTime_; + double VertsPerSec = Model->TotalVertices_ / Model->TotalLoadingTime_; + SystemUtils_->Logger_->Log( + std::string("Model Loading Completed In ") + + std::to_string(Model->TotalLoadingTime_) + + std::string(" Seconds, ") + + std::to_string(Model->TotalVertices_) + + std::string(" Vertices, ") + + std::to_string(VertsPerSec) + + std::string(" Verts/Sec") + ,5); + + + +} + + +void ERS_CLASS_ModelLoader::ReferenceThread() { + + while (!ExitRefThread_) { + + // Extra Scope To Make The Lock Go Out Of Scope Before The Delay Runs + { + // Check Reference List + std::lock_guard LockReferenceThread(BlockRefThread_); + for (unsigned long i = 0; i < ModelsToRefrence_.size(); i++) { + unsigned long TargetID = ModelsToRefrence_[i]->AssetID; + long MatchIndex = CheckIfModelAlreadyLoaded(TargetID); + if (MatchIndex != -1) { + if (LoadedModelRefrences_[MatchIndex]->FullyReady) { + + + std::shared_ptr Target = ModelsToRefrence_[i]; + std::shared_ptr Source = LoadedModelRefrences_[MatchIndex]; + + + + Target->Meshes = Source->Meshes; + //Target->OpenGLTextureIDs_ = Source->OpenGLTextureIDs_; + Target->TextureIDs = Source->TextureIDs; + Target->TotalIndices_ = Source->TotalIndices_; + Target->TotalVertices_ = Source->TotalVertices_; + Target->TotalLoadingTime_ = Source->TotalLoadingTime_; + Target->BoxOffset_ = Source->BoxOffset_; + Target->BoxScale_ = Source->BoxScale_; + Target->IsTemplateModel = false; + Target->FullyReady = true; + + Target->MaxTextureLevel_ = Source->MaxTextureLevel_; + + if (Target->Name == "Loading...") { + Target->Name = Source->Name; + } + + ModelsToRefrence_.erase(ModelsToRefrence_.begin() + i); + break; + } + } + + } + } + std::this_thread::sleep_for(std::chrono::milliseconds(2)); + + + + } + +} + +void ERS_CLASS_ModelLoader::AddModelToReferenceQueue(long AssetID, std::shared_ptr Model) { + + Model->AssetID = AssetID; + ModelsToRefrence_.push_back(Model); + +} + +void ERS_CLASS_ModelLoader::LoadModel(long AssetID, std::shared_ptr Model) { + + // Check If Already In Refs + if (EnableReferenceLoading_) { + std::lock_guard BlockRefThread(BlockRefThread_); + if (CheckIfModelAlreadyLoaded(AssetID) != -1) { + AddModelToReferenceQueue(AssetID, Model); + return; + } + else { + LoadedModelRefrences_.push_back(Model); + + } + } + + // Log Loading For Debugging Purposes + //SystemUtils_->Logger_->Log(std::string(std::string("Loading Model '") + std::to_string(AssetID) + std::string("'")).c_str(), 4); + Model->LoadingStartTime_ = glfwGetTime(); + + // Read Metadata From Asset + std::unique_ptr ModelMetadata = std::make_unique(); + SystemUtils_->ERS_IOSubsystem_->ReadAsset(AssetID, ModelMetadata.get()); + std::string ModelMetadataString = std::string((const char*)ModelMetadata->Data.get()); + YAML::Node Metadata = YAML::Load(ModelMetadataString); + + + ERS_FUNCTION_DecodeModelMetadata(Metadata, Model.get(), SystemUtils_, AssetID, false); + + // Spawn Threads To Load Textures + // std::vector> DecodedTextures; + // for (int i = 0; (long)i < (long)TexturePaths.size(); i++) { + // SystemUtils_->Logger_->Log(std::string(std::string("Assigning Texture To Thread With ID: ") + std::to_string(TextureIDs[i])).c_str(), 4); + // DecodedTextures.push_back(std::async(&ERS_CLASS_ModelLoader::LoadTexture, this, TextureIDs[i], FlipTextures)); + // } + + + // Read Mesh + Assimp::Importer Importer; + //SystemUtils_->Logger_->Log(std::string(std::string("Loading Model With ID: ") + std::to_string(AssetID)).c_str(), 3); + + std::unique_ptr ModelData = std::make_unique(); + SystemUtils_->ERS_IOSubsystem_->ReadAsset(Model->ModelDataID, ModelData.get()); + const aiScene* Scene = Importer.ReadFileFromMemory(ModelData->Data.get(), (int)ModelData->Size_B, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices, ""); + + // Log Errors + if (!Scene || Scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !Scene->mRootNode) { + SystemUtils_->Logger_->Log(std::string(std::string("Model Loading Error: ") + std::string(Importer.GetErrorString())).c_str(), 10); + Model->IsReadyForGPU = false; + return; + } + + // Decode Mesh, Create Texture Pointers + ProcessNode(Model.get(), Scene->mRootNode, Scene); + + // // Get Texture Images From Loader, Push Into Vector + // for (unsigned long i = 0; i < DecodedTextures.size(); i++) { + // SystemUtils_->Logger_->Log(std::string(std::string("Getting Texture With ID: ") + std::to_string(TextureIDs[i])).c_str(), 4); + // Model->TexturesToPushToGPU_.push_back(DecodedTextures[i].get()); + // } + + + // Math Textures To Meshes + MatchTextures(Model.get()); + + + // Set Ready For GPU + Model->IsReadyForGPU = true; +} + +void ERS_CLASS_ModelLoader::MatchTextures(ERS_STRUCT_Model* Model) { + + // Extract Information About Textures For Simplicity + std::vector Meshes; + for (unsigned int i = 0; i < Model->Meshes.size(); i++) { + Meshes.push_back(&Model->Meshes[i]); + } + + // Match + for (unsigned int MeshIndex = 0; MeshIndex < Meshes.size(); MeshIndex++) { + ERS_STRUCT_Mesh* CurrentMesh = Meshes[MeshIndex]; + + // Iterate Over Mesh's Requested Textures, Try To Match With What Model Has + for (unsigned int TextureIndex = 0; TextureIndex < CurrentMesh->Loader_RequestedTextureInformation_.size(); TextureIndex++) { + std::string TextureType = CurrentMesh->Loader_RequestedTextureInformation_[TextureIndex].first; + std::string TextureIdentifier = CurrentMesh->Loader_RequestedTextureInformation_[TextureIndex].second; + + // Now, Search Model's Textures For Match + for (unsigned int ModelTextureIndex = 0; ModelTextureIndex < Model->Textures_.size(); ModelTextureIndex++) { + std::string ModelTextureIdentifier = Model->Textures_[ModelTextureIndex].Path; + + if (ModelTextureIdentifier == TextureIdentifier) { + Model->Textures_[ModelTextureIndex].Type = TextureType; + CurrentMesh->Textures_.push_back(&Model->Textures_[ModelTextureIndex]); + break; + } + + } + + } + + } + +} + + +long ERS_CLASS_ModelLoader::CheckIfModelAlreadyLoaded(long AssetID) { + + long Index = -1; + + // Iterate Through List OF Models Aready Loading/Loaded + for (unsigned long i = 0; i < LoadedModelRefrences_.size(); i++) { + LoadedModelRefrences_[i]->AssetID; + if (LoadedModelRefrences_[i]->AssetID == AssetID) { + Index = i; + } + } + + return Index; + +} + +void ERS_CLASS_ModelLoader::ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene) { + + + // Process Meshes In Current Node + for (unsigned int i = 0; i < Node->mNumMeshes; i++) { + aiMesh* Mesh = Scene->mMeshes[Node->mMeshes[i]]; + ProcessMesh( + Model, + (unsigned long)Mesh->mNumVertices, + (unsigned long)Mesh->mNumFaces*3, + Mesh, + Scene + ); + + } + + // Process Children Nodes + for (unsigned int i = 0; i < Node->mNumChildren; i++) { + ProcessNode(Model, Node->mChildren[i], Scene); + } + + +} + +ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PreallocIndSize, aiMesh *Mesh, const aiScene *Scene) { + + // Create Data Holders + ERS_STRUCT_Mesh OutputMesh; + OutputMesh = Model->Meshes[Model->NumMeshes_]; + + + + OutputMesh.Vertices.reserve(PreallocVertSize); + OutputMesh.Indices.reserve(PreallocIndSize); + + // Iterate Through Meshes' Vertices + for (unsigned int i = 0; i < Mesh->mNumVertices; i++) { + + // Hold Vertex Data + ERS_STRUCT_Vertex Vertex; + glm::vec3 Vector; + + + Vector.x = Mesh->mVertices[i].x; + Vector.y = Mesh->mVertices[i].y; + Vector.z = Mesh->mVertices[i].z; + Vertex.Position = Vector - Model->BoxOffset_; + + if (Mesh->HasNormals()) + { + Vector.x = Mesh->mNormals[i].x; + Vector.y = Mesh->mNormals[i].y; + Vector.z = Mesh->mNormals[i].z; + Vertex.Normal = Vector; + } + + if (Mesh->mTextureCoords[0]) { + + glm::vec2 Vec; + + // Get Texture Coordinates + Vec.x = Mesh->mTextureCoords[0][i].x; + Vec.y = Mesh->mTextureCoords[0][i].y; + Vertex.TexCoords = Vec; + + // Tangent + Vector.x = Mesh->mTangents[i].x; + Vector.y = Mesh->mTangents[i].y; + Vector.z = Mesh->mTangents[i].z; + Vertex.Tangent = Vector; + + // Bitangent + Vector.x = Mesh->mBitangents[i].x; + Vector.y = Mesh->mBitangents[i].y; + Vector.z = Mesh->mBitangents[i].z; + Vertex.Bitangent = Vector; + + } else { + Vertex.TexCoords = glm::vec2(0.0f, 0.0f); + } + + OutputMesh.Vertices.push_back(Vertex); + + + + } + + // Iterate Through Faces + for (unsigned int i = 0; i < Mesh->mNumFaces; i++) { + + aiFace Face = Mesh->mFaces[i]; + + // Get Face Indices + for (unsigned int j = 0; j < Face.mNumIndices; j++) { + OutputMesh.Indices.push_back(Face.mIndices[j]); + } + } + + // Process Materials + aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; + IdentifyMeshTextures(Material, &OutputMesh); + + + // Return Populated Mesh + Model->Meshes[Model->NumMeshes_] = OutputMesh; + Model->NumMeshes_++; + + return OutputMesh; + +} + +void ERS_CLASS_ModelLoader::IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh) { + + std::vector> TextureTypes; + TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT, "texture_ambient")); + TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT_OCCLUSION, "texture_ambient_occlusion")); + TextureTypes.push_back(std::make_pair(aiTextureType_BASE_COLOR, "texture_base_color")); + TextureTypes.push_back(std::make_pair(aiTextureType_DIFFUSE, "texture_diffuse")); + TextureTypes.push_back(std::make_pair(aiTextureType_DIFFUSE_ROUGHNESS, "texture_diffuse_roughness")); + TextureTypes.push_back(std::make_pair(aiTextureType_DISPLACEMENT, "texture_displacement")); + TextureTypes.push_back(std::make_pair(aiTextureType_EMISSION_COLOR, "texture_emission_color")); + TextureTypes.push_back(std::make_pair(aiTextureType_EMISSIVE, "texture_emissive")); + TextureTypes.push_back(std::make_pair(aiTextureType_HEIGHT, "texture_height")); + TextureTypes.push_back(std::make_pair(aiTextureType_LIGHTMAP, "texture_lightmap")); + TextureTypes.push_back(std::make_pair(aiTextureType_METALNESS, "texture_metalness")); + TextureTypes.push_back(std::make_pair(aiTextureType_NONE, "texture_none")); + TextureTypes.push_back(std::make_pair(aiTextureType_NORMAL_CAMERA, "texture_normal_camera")); + TextureTypes.push_back(std::make_pair(aiTextureType_NORMALS, "texture_normals")); + TextureTypes.push_back(std::make_pair(aiTextureType_OPACITY, "texture_opacity")); + TextureTypes.push_back(std::make_pair(aiTextureType_REFLECTION, "texture_reflection")); + TextureTypes.push_back(std::make_pair(aiTextureType_SHININESS, "texture_shininess")); + TextureTypes.push_back(std::make_pair(aiTextureType_SPECULAR, "texture_specular")); + TextureTypes.push_back(std::make_pair(aiTextureType_UNKNOWN, "texture_unknown")); + + // Iterate Over All Texture Types + for (unsigned int TextureTypeIndex = 0; TextureTypeIndex < TextureTypes.size(); TextureTypeIndex++) { + + aiTextureType Type = TextureTypes[TextureTypeIndex].first; + std::string TypeName = TextureTypes[TextureTypeIndex].second; + + // Iterate Through Textures For This Type + for (unsigned int i=0; i< Mat->GetTextureCount(Type); i++) { + + + // Calculate Texture Path + aiString TextureString; + Mat->GetTexture(Type, i, &TextureString); + std::string TextureIdentifier = std::string(std::string(TextureString.C_Str())); + + //std::string Message = std::string("Model Requesting Texture Of Type '") + TypeName + std::string("' With Identifier '") + TextureIdentifier + std::string("'"); + //SystemUtils_->Logger_->Log(Message, 3); + + // Search Texture List For Index Of Same Match, Add To List Of Unique Textures If Not Found + bool AlreadyHasTexture = false; + for (unsigned long x = 0; x < Mesh->Loader_RequestedTextureInformation_.size(); x++) { + if (Mesh->Loader_RequestedTextureInformation_[x].second == TextureIdentifier) { + SystemUtils_->Logger_->Log(std::string("Found Matching Texture '") + Mesh->Loader_RequestedTextureInformation_[x].second + "'", 3); + AlreadyHasTexture = true; + break; + } + } + + // If It's Not Already In The List, Add IT + if (!AlreadyHasTexture) { + Mesh->Loader_RequestedTextureInformation_.push_back(std::make_pair(TypeName, TextureIdentifier)); + } + + + } + + } + +} + diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h new file mode 100644 index 0000000000..9ebb1e6cb0 --- /dev/null +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h @@ -0,0 +1,215 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include +#include + +#include + +//#define STB_IMAGE_IMPLEMENTATION +//#include + +#include +#include +#include + +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include + +#include + +#include + +// TESTING STUFF HERE +#include + + + + + + + +/** + * @brief Class for loading models (fbx, gltx, etc.) based on the ASSIMP library + * + */ +class ERS_CLASS_ModelLoader { + + +private: + + + + ERS_STRUCT_SystemUtils* SystemUtils_; /**> WorkItems_; /** WorkIDs_; /** FlipTextures_; /**> LoadedModelRefrences_; /**> ModelsToRefrence_; /** WorkerThreads_; /** Model); + + /** + * @brief Creates texture pointers within the model's meshes + * + * @param Model + */ + void MatchTextures(ERS_STRUCT_Model* Model); + + + +public: + + std::unique_ptr AssetStreamingManager_; /** Model); /** Model); + + + /** + * @brief Process models in scene, perform opengl loading operations on models as needed - opengl cannot be done in another thread. + * + * @param ActiveScene + */ + void ProcessNewModels(ERS_STRUCT_Scene* ActiveScene); + + + /** + * @brief Add a model to the queue to be loaded. + * + * @param AssetID + * @param Model + * @param FlipTextures + */ + void AddModelToLoadingQueue(long AssetID, std::shared_ptr Model); + void AddModelToLoadingQueue(std::shared_ptr Model); + + + +}; + From 9eb2316d819d6243c99b4530531052e6d7787585 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:34:31 +0000 Subject: [PATCH 17/33] Implement New Model Format Loader --- ..._FUNCTION_Legacy_PreprocessTextureInfo.cpp | 354 +----------------- ...RS_FUNCTION_Legacy_PreprocessTextureInfo.h | 101 +---- 2 files changed, 2 insertions(+), 453 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index 5b3676d0cf..2092f9506b 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -2,363 +2,11 @@ // This file is part of the BrainGenix-ERS Environment Rendering System // //======================================================================// -#include +#include -// FIXME: -// Cleanup Doxygen, fix headers, etc. -// optionally optimize processgpu function to provide least amount of lag as possible -// Add Placeholder meshes during loading - -ERS_CLASS_ModelLoader::ERS_CLASS_ModelLoader(ERS_STRUCT_SystemUtils* SystemUtils, int MaxModelLoadingThreads) { - - SystemUtils_ = SystemUtils; - SystemUtils_->Logger_->Log("Initializing Model Loader", 5); - FreeImage_Initialise(); - - - - AssetStreamingManager_ = std::make_unique(SystemUtils_); - - - - if (MaxModelLoadingThreads == -1) { - SystemUtils_->Logger_->Log("Identifying Number Of CPU Cores", 4); - MaxModelLoadingThreads = std::thread::hardware_concurrency(); - SystemUtils_->Logger_->Log(std::string(std::string("Identified ") + std::to_string(MaxModelLoadingThreads) + std::string(" Cores")).c_str(), 4); - } - SystemUtils_->Logger_->Log(std::string(std::string("Creating ") + std::to_string(MaxModelLoadingThreads) + std::string("Model Loading Threads")).c_str(), 4); - for (int i = 0; i < MaxModelLoadingThreads; i++) { - SystemUtils_->Logger_->Log(std::string(std::string("Creating Worker Thread ") + std::to_string(i)).c_str(), 3); - WorkerThreads_.push_back(std::thread(&ERS_CLASS_ModelLoader::WorkerThread, this, i)); - } - - //SystemUtils_->Logger_->Log("Creating Reference Loading Thread", 5); - //ModelRefrenceThread_ = std::thread(&ERS_CLASS_ModelLoader::ReferenceThread, this); - - -} - -ERS_CLASS_ModelLoader::~ERS_CLASS_ModelLoader() { - - SystemUtils_->Logger_->Log("ERS_CLASS_ModelLoader Destructor Called", 6); - FreeImage_DeInitialise(); - - - - // Shutdown Threads - SystemUtils_->Logger_->Log("Sending Join Command To Worker Threads", 5); - BlockThread_.lock(); - ExitThreads_ = true; - BlockThread_.unlock(); - - SystemUtils_->Logger_->Log("Joining Worker Threads", 6); - for (int i = 0; (long)i < (long)WorkerThreads_.size(); i++) { - SystemUtils_->Logger_->Log(std::string(std::string("Joining Worker Thread ") + std::to_string(i)).c_str(), 3); - WorkerThreads_[i].join(); - } - SystemUtils_->Logger_->Log("Finished Joining Worker Threads", 6); - - - // SystemUtils_->Logger_->Log("Sending Join Command To Reference Thread", 5); - // std::lock_guard Deleteme(BlockRefThread_); - // ExitRefThread_ = true; - - // SystemUtils_->Logger_->Log("Joining Reference Loader Thread", 5); - // ModelRefrenceThread_.join(); - // SystemUtils_->Logger_->Log("Finished Joining Reference Loader Thread", 5); - - -} - -void ERS_CLASS_ModelLoader::WorkerThread(int WorkerThreadNumber) { - - std::string ThreadName = std::string("ERS_GLT-") + std::to_string(WorkerThreadNumber); - SetThreadName(ThreadName); - - bool ThreadShouldRun = true; - while (ThreadShouldRun) { - - // Acquire Check Lock - BlockThread_.lock(); - if (ExitThreads_) { - ThreadShouldRun = false; - BlockThread_.unlock(); - } else { - - // Check If Items In Work Queue - int Size = WorkItems_.size(); - if (Size > 0) { - - // Get Item, Remove From Queue, Unlock - std::shared_ptr WorkItem = WorkItems_[0]; - long WorkID = WorkIDs_[0]; - - - WorkItems_.erase(WorkItems_.begin()); - WorkIDs_.erase(WorkIDs_.begin()); - - - BlockThread_.unlock(); - - // Process Item - LoadModel(WorkID, WorkItem); - - } else { - - // No Work Items, Unlock Mutex, Sleep Thread - BlockThread_.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - - } - } - - - } - -} - -void ERS_CLASS_ModelLoader::ProcessNewModels(ERS_STRUCT_Scene* ActiveScene) { - - // Check List Of Models - for (unsigned long i = 0; i Models.size(); i++) { - - if ( (ActiveScene->Models[i]->IsReadyForGPU) && !(ActiveScene->Models[i]->FullyReady) ) { - - SystemUtils_->Logger_->Log(std::string(std::string("Pushing Material Information To GPU For Asset: ") + std::to_string(ActiveScene->Models[i]->AssetID)).c_str(), 4); - - ProcessGPU(ActiveScene->Models[i]); - ActiveScene->Models[i]->FullyReady = true; - - } - - } - -} - -void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(std::shared_ptr Model) { - AddModelToLoadingQueue(Model->AssetID, Model); -} - -void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(long AssetID, std::shared_ptr Model) { - - // Log Addition - SystemUtils_->Logger_->Log(std::string(std::string("Adding Model '") + std::to_string(AssetID) + std::string("' To Load Queue")).c_str(), 4); - - // Add To Queue - BlockThread_.lock(); - - WorkIDs_.push_back(AssetID); - WorkItems_.push_back(Model); - - - BlockThread_.unlock(); - -} - - -void ERS_CLASS_ModelLoader::ProcessGPU(std::shared_ptr Model) { - - - - // // Push Textures To GPU RAM - // for (unsigned long i = 0; i < Model->TexturesToPushToGPU_.size(); i++) { - - // // Generate Texture - // unsigned int TextureID; - // glGenTextures(1, &TextureID); - // glBindTexture(GL_TEXTURE_2D, TextureID); - - // // Set Texture Properties - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - - // // Convert FIBITMAP* To Raw Image Bytes - // unsigned char* RawImageData = Model->TexturesToPushToGPU_[i].ImageBytes; - - // if (RawImageData != NULL) { - // if (Model->TexturesToPushToGPU_[i].FreeImageBackend) { - // if (Model->TexturesToPushToGPU_[i].Channels == 4) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, RawImageData); - // } else if (Model->TexturesToPushToGPU_[i].Channels == 3) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_BGR, GL_UNSIGNED_BYTE, RawImageData); - // } else if (Model->TexturesToPushToGPU_[i].Channels == 2) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RG, GL_UNSIGNED_BYTE, RawImageData); - // } else if (Model->TexturesToPushToGPU_[i].Channels == 1) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RED, GL_UNSIGNED_BYTE, RawImageData); - // } else { - // SystemUtils_->Logger_->Log(std::string("Texture With ID '") + Model->TexturesToPushToGPU_[i].Path + std::string("' For Model '") + Model->Name + std::string("' Has Unsupported Number Of Channels: ") + std::to_string(Model->TexturesToPushToGPU_[i].Channels), 8); - // } - // } else { - // if (Model->TexturesToPushToGPU_[i].Channels == 4) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, RawImageData); - // } else if (Model->TexturesToPushToGPU_[i].Channels == 3) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RGB, GL_UNSIGNED_BYTE, RawImageData); - // } else if (Model->TexturesToPushToGPU_[i].Channels == 2) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RG, GL_UNSIGNED_BYTE, RawImageData); - // } else if (Model->TexturesToPushToGPU_[i].Channels == 1) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, Model->TexturesToPushToGPU_[i].Width, Model->TexturesToPushToGPU_[i].Height, 0, GL_RED, GL_UNSIGNED_BYTE, RawImageData); - // } else { - // SystemUtils_->Logger_->Log(std::string("Texture With ID '") + Model->TexturesToPushToGPU_[i].Path + std::string("' For Model '") + Model->Name + std::string("' Has Unsupported Number Of Channels: ") + std::to_string(Model->TexturesToPushToGPU_[i].Channels), 8); - // } - // } - - // glGenerateMipmap(GL_TEXTURE_2D); - - // } else { - // SystemUtils_->Logger_->Log("Texture Failed To Load, Cannot Push To GPU", 9); - // } - - - - // // Unload Image Data - // if (Model->TexturesToPushToGPU_[i].FreeImageBackend) { - // FreeImage_Unload(Model->TexturesToPushToGPU_[i].ImageData); - // } else { - // stbi_image_free(Model->TexturesToPushToGPU_[i].ImageBytes); - // } - - // // Append To Texture Index - // Model->OpenGLTextureIDs_.push_back(TextureID); - // } - - - - // Erase List To Save Memory - //Model->TexturesToPushToGPU_.erase(Model->TexturesToPushToGPU_.begin(), Model->TexturesToPushToGPU_.end()); - Model->IsTemplateModel = true; - - - - // Collect Vertex Count Analytics - for (unsigned long i = 0; i < Model->Meshes.size(); i++) { - Model->TotalVertices_ += Model->Meshes[i].Vertices.size(); - Model->TotalIndices_ += Model->Meshes[i].Indices.size(); - } - - // Process Texture References, Setup Meshes - for (unsigned long i = 0; i < Model->Meshes.size(); i++) { - - // Set Shadow Configuration Pointers - Model->Meshes[i].CastDynamicShadows_ = &Model->CastDynamicShadows_; - Model->Meshes[i].CastStaticShadows_ = &Model->CastStaticShadows_; - Model->Meshes[i].ReceiveShadows_ = &Model->ReceiveShadows_; - - - // for (unsigned long Index = 0; Index < Model->Meshes[i].TextureReferences_.size(); Index++) { // IF TEXTURES DONT WORK, CHECK HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - // int TextureIndex = Model->Meshes[i].TextureReferences_[Index]; - - // if (TextureIndex == -1) { - // SystemUtils_->Logger_->Log("Failed To Find Corresponding Texture", 8); - // Model->Meshes[i].TextureIDs.push_back(-1); - // Model->Meshes[i].TextureColorChannels_.push_back(0); - // } else { - // Model->Meshes[i].TextureIDs.push_back(Model->OpenGLTextureIDs_[TextureIndex]); - // Model->Meshes[i].TextureColorChannels_.push_back(Model->TexturesToPushToGPU_[TextureIndex].Channels); - // } - - - // } - Model->Meshes[i].SetupMesh(); - // Perhaps save mem by erasing the vertices after pusning? (also indices) - } - - - Model->LoadingFinishTime_ = glfwGetTime(); - Model->TotalLoadingTime_ = Model->LoadingFinishTime_ - Model->LoadingStartTime_; - double VertsPerSec = Model->TotalVertices_ / Model->TotalLoadingTime_; - SystemUtils_->Logger_->Log( - std::string("Model Loading Completed In ") - + std::to_string(Model->TotalLoadingTime_) - + std::string(" Seconds, ") - + std::to_string(Model->TotalVertices_) - + std::string(" Vertices, ") - + std::to_string(VertsPerSec) - + std::string(" Verts/Sec") - ,5); - - - -} - - -void ERS_CLASS_ModelLoader::ReferenceThread() { - - while (!ExitRefThread_) { - - // Extra Scope To Make The Lock Go Out Of Scope Before The Delay Runs - { - // Check Reference List - std::lock_guard LockReferenceThread(BlockRefThread_); - for (unsigned long i = 0; i < ModelsToRefrence_.size(); i++) { - unsigned long TargetID = ModelsToRefrence_[i]->AssetID; - long MatchIndex = CheckIfModelAlreadyLoaded(TargetID); - if (MatchIndex != -1) { - if (LoadedModelRefrences_[MatchIndex]->FullyReady) { - - - std::shared_ptr Target = ModelsToRefrence_[i]; - std::shared_ptr Source = LoadedModelRefrences_[MatchIndex]; - - - - Target->Meshes = Source->Meshes; - //Target->OpenGLTextureIDs_ = Source->OpenGLTextureIDs_; - Target->TextureIDs = Source->TextureIDs; - Target->TotalIndices_ = Source->TotalIndices_; - Target->TotalVertices_ = Source->TotalVertices_; - Target->TotalLoadingTime_ = Source->TotalLoadingTime_; - Target->BoxOffset_ = Source->BoxOffset_; - Target->BoxScale_ = Source->BoxScale_; - Target->IsTemplateModel = false; - Target->FullyReady = true; - - Target->MaxTextureLevel_ = Source->MaxTextureLevel_; - - if (Target->Name == "Loading...") { - Target->Name = Source->Name; - } - - ModelsToRefrence_.erase(ModelsToRefrence_.begin() + i); - break; - } - } - - } - } - std::this_thread::sleep_for(std::chrono::milliseconds(2)); - - - - } - -} - -void ERS_CLASS_ModelLoader::AddModelToReferenceQueue(long AssetID, std::shared_ptr Model) { - - Model->AssetID = AssetID; - ModelsToRefrence_.push_back(Model); - -} void ERS_CLASS_ModelLoader::LoadModel(long AssetID, std::shared_ptr Model) { - // Check If Already In Refs - if (EnableReferenceLoading_) { - std::lock_guard BlockRefThread(BlockRefThread_); - if (CheckIfModelAlreadyLoaded(AssetID) != -1) { - AddModelToReferenceQueue(AssetID, Model); - return; - } - else { - LoadedModelRefrences_.push_back(Model); - - } - } - // Log Loading For Debugging Purposes //SystemUtils_->Logger_->Log(std::string(std::string("Loading Model '") + std::to_string(AssetID) + std::string("'")).c_str(), 4); Model->LoadingStartTime_ = glfwGetTime(); diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h index 9ebb1e6cb0..24e8a6ad54 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h @@ -26,14 +26,10 @@ #include -//#define STB_IMAGE_IMPLEMENTATION -//#include - #include #include #include -#include // Internal Libraries (BG convention: use <> instead of "") #include @@ -43,60 +39,21 @@ #include -#include - -// TESTING STUFF HERE -#include - - - - - -/** - * @brief Class for loading models (fbx, gltx, etc.) based on the ASSIMP library - * - */ -class ERS_CLASS_ModelLoader { -private: +void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_Model* Model, ERS_STRUCT_SystemUtils* SystemUtils, long AssetID, bool LogEnable); - ERS_STRUCT_SystemUtils* SystemUtils_; /**> WorkItems_; /** WorkIDs_; /** FlipTextures_; /**> LoadedModelRefrences_; /**> ModelsToRefrence_; /** WorkerThreads_; /** AssetStreamingManager_; /** Model); /** Model); - - - /** - * @brief Process models in scene, perform opengl loading operations on models as needed - opengl cannot be done in another thread. - * - * @param ActiveScene - */ - void ProcessNewModels(ERS_STRUCT_Scene* ActiveScene); - - - /** - * @brief Add a model to the queue to be loaded. - * - * @param AssetID - * @param Model - * @param FlipTextures - */ - void AddModelToLoadingQueue(long AssetID, std::shared_ptr Model); - void AddModelToLoadingQueue(std::shared_ptr Model); - - - -}; - From a33ba225cc737660394999d1aa4930d7db165005 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:39:21 +0000 Subject: [PATCH 18/33] Implement New Model Format Loader --- .../ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp | 6 +- ..._FUNCTION_Legacy_PreprocessTextureInfo.cpp | 86 ++----------------- 2 files changed, 11 insertions(+), 81 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp index 5b3676d0cf..4d555ef7ac 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp @@ -563,9 +563,9 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi } } - // Process Materials - aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; - IdentifyMeshTextures(Material, &OutputMesh); + // // Process Materials + // aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; + // IdentifyMeshTextures(Material, &OutputMesh); // Return Populated Mesh diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index 2092f9506b..01e7cb992f 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -119,12 +119,14 @@ void ERS_CLASS_ModelLoader::ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, c // Process Meshes In Current Node for (unsigned int i = 0; i < Node->mNumMeshes; i++) { aiMesh* Mesh = Scene->mMeshes[Node->mMeshes[i]]; - ProcessMesh( - Model, - (unsigned long)Mesh->mNumVertices, - (unsigned long)Mesh->mNumFaces*3, - Mesh, - Scene + Model->Meshes_.push_back( + ProcessMesh( + Model, + (unsigned long)Mesh->mNumVertices, + (unsigned long)Mesh->mNumFaces*3, + Mesh, + Scene + ) ); } @@ -141,75 +143,6 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi // Create Data Holders ERS_STRUCT_Mesh OutputMesh; - OutputMesh = Model->Meshes[Model->NumMeshes_]; - - - - OutputMesh.Vertices.reserve(PreallocVertSize); - OutputMesh.Indices.reserve(PreallocIndSize); - - // Iterate Through Meshes' Vertices - for (unsigned int i = 0; i < Mesh->mNumVertices; i++) { - - // Hold Vertex Data - ERS_STRUCT_Vertex Vertex; - glm::vec3 Vector; - - - Vector.x = Mesh->mVertices[i].x; - Vector.y = Mesh->mVertices[i].y; - Vector.z = Mesh->mVertices[i].z; - Vertex.Position = Vector - Model->BoxOffset_; - - if (Mesh->HasNormals()) - { - Vector.x = Mesh->mNormals[i].x; - Vector.y = Mesh->mNormals[i].y; - Vector.z = Mesh->mNormals[i].z; - Vertex.Normal = Vector; - } - - if (Mesh->mTextureCoords[0]) { - - glm::vec2 Vec; - - // Get Texture Coordinates - Vec.x = Mesh->mTextureCoords[0][i].x; - Vec.y = Mesh->mTextureCoords[0][i].y; - Vertex.TexCoords = Vec; - - // Tangent - Vector.x = Mesh->mTangents[i].x; - Vector.y = Mesh->mTangents[i].y; - Vector.z = Mesh->mTangents[i].z; - Vertex.Tangent = Vector; - - // Bitangent - Vector.x = Mesh->mBitangents[i].x; - Vector.y = Mesh->mBitangents[i].y; - Vector.z = Mesh->mBitangents[i].z; - Vertex.Bitangent = Vector; - - } else { - Vertex.TexCoords = glm::vec2(0.0f, 0.0f); - } - - OutputMesh.Vertices.push_back(Vertex); - - - - } - - // Iterate Through Faces - for (unsigned int i = 0; i < Mesh->mNumFaces; i++) { - - aiFace Face = Mesh->mFaces[i]; - - // Get Face Indices - for (unsigned int j = 0; j < Face.mNumIndices; j++) { - OutputMesh.Indices.push_back(Face.mIndices[j]); - } - } // Process Materials aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; @@ -217,9 +150,6 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi // Return Populated Mesh - Model->Meshes[Model->NumMeshes_] = OutputMesh; - Model->NumMeshes_++; - return OutputMesh; } From 217f6d08f452503a704fc0d04dc623092c567c95 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:42:42 +0000 Subject: [PATCH 19/33] Implement New Model Format Loader --- ..._FUNCTION_Legacy_PreprocessTextureInfo.cpp | 7 +- ...RS_FUNCTION_Legacy_PreprocessTextureInfo.h | 105 ++++++++---------- 2 files changed, 50 insertions(+), 62 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index 01e7cb992f..e69d4d76eb 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -136,17 +136,16 @@ void ERS_CLASS_ModelLoader::ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, c ProcessNode(Model, Node->mChildren[i], Scene); } - } -ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PreallocIndSize, aiMesh *Mesh, const aiScene *Scene) { +ERS_STRUCT_Mesh ERS_LEGACY_FUNCTION_ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PreallocIndSize, aiMesh *Mesh, const aiScene *Scene) { // Create Data Holders ERS_STRUCT_Mesh OutputMesh; // Process Materials aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; - IdentifyMeshTextures(Material, &OutputMesh); + ERS_LEGACY_FUNCTION_IdentifyMeshTextures(Material, &OutputMesh); // Return Populated Mesh @@ -154,7 +153,7 @@ ERS_STRUCT_Mesh ERS_CLASS_ModelLoader::ProcessMesh(ERS_STRUCT_Model* Model, unsi } -void ERS_CLASS_ModelLoader::IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh) { +void ERS_LEGACY_FUNCTION_IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh) { std::vector> TextureTypes; TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT, "texture_ambient")); diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h index 24e8a6ad54..fd486939b8 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h @@ -50,67 +50,56 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_M +/** + * @brief Load a texture given the id + * + * @param ID + * @param FlipTextures + * @return ERS_STRUCT_Texture + */ +ERS_STRUCT_Texture ERS_LEGACY_FUNCTION_LoadTexture(long ID, bool FlipTextures = false); +/** + * @brief Populates Texture Request Information For The Mesh + * + * @param Mat + * @param Mesh + */ +void ERS_LEGACY_FUNCTION_IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh); - /** - * @brief Load a texture given the id - * - * @param ID - * @param FlipTextures - * @return ERS_STRUCT_Texture - */ - ERS_STRUCT_Texture LoadTexture(long ID, bool FlipTextures = false); - - /** - * @brief Function Used To Process Subnodes Of SceneFiles. - * - * @param Node - * @param Scene - */ - void ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene); - - /** - * @brief Process Meshes From Model. - * - * @param Model - * @param Mesh - * @param Scene - * @return ERS_STRUCT_Mesh - */ - ERS_STRUCT_Mesh ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PerallocIndSize, aiMesh *Mesh, const aiScene *Scene); - - - /** - * @brief Populates Texture Request Information For The Mesh - * - * @param Mat - * @param Mesh - */ - void IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh); - - /** - * @brief Checks if the target model has already been loaded, and returns refrences when completed. - * - * @param AssetID - * @return long - */ - long CheckIfModelAlreadyLoaded(long AssetID); - - /** - * @brief Adds the given model to the queue of models with refs waiting to be copied - * - * @param AssetID - * @param Model - */ - void AddModelToReferenceQueue(long AssetID, std::shared_ptr Model); - - /** - * @brief Creates texture pointers within the model's meshes - * - * @param Model - */ - void MatchTextures(ERS_STRUCT_Model* Model); + +/** + * @brief Function Used To Process Subnodes Of SceneFiles. + * + * @param Node + * @param Scene + */ +void ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene); + +/** + * @brief Process Meshes From Model. + * + * @param Model + * @param Mesh + * @param Scene + * @return ERS_STRUCT_Mesh + */ +ERS_STRUCT_Mesh ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PerallocIndSize, aiMesh *Mesh, const aiScene *Scene); + + + + + + + + +/** + * @brief Creates texture pointers within the model's meshes + * + * @param Model + */ +void MatchTextures(ERS_STRUCT_Model* Model); From c105325fbbdbec36f3fca5608d28490089ad1919 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:46:36 +0000 Subject: [PATCH 20/33] Implement New Model Format Loader --- ..._FUNCTION_Legacy_PreprocessTextureInfo.cpp | 95 ++----------------- 1 file changed, 7 insertions(+), 88 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index e69d4d76eb..87c6fe48db 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -5,33 +5,16 @@ #include -void ERS_CLASS_ModelLoader::LoadModel(long AssetID, std::shared_ptr Model) { - - // Log Loading For Debugging Purposes - //SystemUtils_->Logger_->Log(std::string(std::string("Loading Model '") + std::to_string(AssetID) + std::string("'")).c_str(), 4); - Model->LoadingStartTime_ = glfwGetTime(); +void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_Model* Model, ERS_STRUCT_SystemUtils* SystemUtils, long AssetID, bool LogEnable) { // Read Metadata From Asset std::unique_ptr ModelMetadata = std::make_unique(); - SystemUtils_->ERS_IOSubsystem_->ReadAsset(AssetID, ModelMetadata.get()); + SystemUtils->ERS_IOSubsystem_->ReadAsset(AssetID, ModelMetadata.get()); std::string ModelMetadataString = std::string((const char*)ModelMetadata->Data.get()); YAML::Node Metadata = YAML::Load(ModelMetadataString); - - ERS_FUNCTION_DecodeModelMetadata(Metadata, Model.get(), SystemUtils_, AssetID, false); - - // Spawn Threads To Load Textures - // std::vector> DecodedTextures; - // for (int i = 0; (long)i < (long)TexturePaths.size(); i++) { - // SystemUtils_->Logger_->Log(std::string(std::string("Assigning Texture To Thread With ID: ") + std::to_string(TextureIDs[i])).c_str(), 4); - // DecodedTextures.push_back(std::async(&ERS_CLASS_ModelLoader::LoadTexture, this, TextureIDs[i], FlipTextures)); - // } - - // Read Mesh Assimp::Importer Importer; - //SystemUtils_->Logger_->Log(std::string(std::string("Loading Model With ID: ") + std::to_string(AssetID)).c_str(), 3); - std::unique_ptr ModelData = std::make_unique(); SystemUtils_->ERS_IOSubsystem_->ReadAsset(Model->ModelDataID, ModelData.get()); const aiScene* Scene = Importer.ReadFileFromMemory(ModelData->Data.get(), (int)ModelData->Size_B, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices, ""); @@ -44,83 +27,22 @@ void ERS_CLASS_ModelLoader::LoadModel(long AssetID, std::shared_ptrmRootNode, Scene); - - // // Get Texture Images From Loader, Push Into Vector - // for (unsigned long i = 0; i < DecodedTextures.size(); i++) { - // SystemUtils_->Logger_->Log(std::string(std::string("Getting Texture With ID: ") + std::to_string(TextureIDs[i])).c_str(), 4); - // Model->TexturesToPushToGPU_.push_back(DecodedTextures[i].get()); - // } - + ERS_LEGACY_FUNCTION_ProcessNode(Model.get(), Scene->mRootNode, Scene); - // Math Textures To Meshes - MatchTextures(Model.get()); - - - // Set Ready For GPU - Model->IsReadyForGPU = true; } -void ERS_CLASS_ModelLoader::MatchTextures(ERS_STRUCT_Model* Model) { - // Extract Information About Textures For Simplicity - std::vector Meshes; - for (unsigned int i = 0; i < Model->Meshes.size(); i++) { - Meshes.push_back(&Model->Meshes[i]); - } - // Match - for (unsigned int MeshIndex = 0; MeshIndex < Meshes.size(); MeshIndex++) { - ERS_STRUCT_Mesh* CurrentMesh = Meshes[MeshIndex]; - - // Iterate Over Mesh's Requested Textures, Try To Match With What Model Has - for (unsigned int TextureIndex = 0; TextureIndex < CurrentMesh->Loader_RequestedTextureInformation_.size(); TextureIndex++) { - std::string TextureType = CurrentMesh->Loader_RequestedTextureInformation_[TextureIndex].first; - std::string TextureIdentifier = CurrentMesh->Loader_RequestedTextureInformation_[TextureIndex].second; - - // Now, Search Model's Textures For Match - for (unsigned int ModelTextureIndex = 0; ModelTextureIndex < Model->Textures_.size(); ModelTextureIndex++) { - std::string ModelTextureIdentifier = Model->Textures_[ModelTextureIndex].Path; - - if (ModelTextureIdentifier == TextureIdentifier) { - Model->Textures_[ModelTextureIndex].Type = TextureType; - CurrentMesh->Textures_.push_back(&Model->Textures_[ModelTextureIndex]); - break; - } - } - } - - } - -} - - -long ERS_CLASS_ModelLoader::CheckIfModelAlreadyLoaded(long AssetID) { - - long Index = -1; - - // Iterate Through List OF Models Aready Loading/Loaded - for (unsigned long i = 0; i < LoadedModelRefrences_.size(); i++) { - LoadedModelRefrences_[i]->AssetID; - if (LoadedModelRefrences_[i]->AssetID == AssetID) { - Index = i; - } - } - - return Index; - -} - -void ERS_CLASS_ModelLoader::ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene) { +void ERS_LEGACY_FUNCTION_ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene) { // Process Meshes In Current Node for (unsigned int i = 0; i < Node->mNumMeshes; i++) { aiMesh* Mesh = Scene->mMeshes[Node->mMeshes[i]]; - Model->Meshes_.push_back( - ProcessMesh( + Model->Meshes.push_back( + ERS_LEGACY_FUNCTION_ProcessMesh( Model, (unsigned long)Mesh->mNumVertices, (unsigned long)Mesh->mNumFaces*3, @@ -133,7 +55,7 @@ void ERS_CLASS_ModelLoader::ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, c // Process Children Nodes for (unsigned int i = 0; i < Node->mNumChildren; i++) { - ProcessNode(Model, Node->mChildren[i], Scene); + ERS_LEGACY_FUNCTION_ProcessNode(Model, Node->mChildren[i], Scene); } } @@ -191,9 +113,6 @@ void ERS_LEGACY_FUNCTION_IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mat->GetTexture(Type, i, &TextureString); std::string TextureIdentifier = std::string(std::string(TextureString.C_Str())); - //std::string Message = std::string("Model Requesting Texture Of Type '") + TypeName + std::string("' With Identifier '") + TextureIdentifier + std::string("'"); - //SystemUtils_->Logger_->Log(Message, 3); - // Search Texture List For Index Of Same Match, Add To List Of Unique Textures If Not Found bool AlreadyHasTexture = false; for (unsigned long x = 0; x < Mesh->Loader_RequestedTextureInformation_.size(); x++) { From b2984d3c45c275c027482cd4f148987bbdeb03dd Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:48:01 +0000 Subject: [PATCH 21/33] Implement New Model Format Loader --- ..._FUNCTION_Legacy_PreprocessTextureInfo.cpp | 5 +-- ...RS_FUNCTION_Legacy_PreprocessTextureInfo.h | 42 +++++-------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index 87c6fe48db..256d75ffa2 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -16,7 +16,7 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_M // Read Mesh Assimp::Importer Importer; std::unique_ptr ModelData = std::make_unique(); - SystemUtils_->ERS_IOSubsystem_->ReadAsset(Model->ModelDataID, ModelData.get()); + SystemUtils->ERS_IOSubsystem_->ReadAsset(Model->ModelDataID, ModelData.get()); const aiScene* Scene = Importer.ReadFileFromMemory(ModelData->Data.get(), (int)ModelData->Size_B, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices, ""); // Log Errors @@ -27,7 +27,7 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_M } // Decode Mesh, Create Texture Pointers - ERS_LEGACY_FUNCTION_ProcessNode(Model.get(), Scene->mRootNode, Scene); + ERS_LEGACY_FUNCTION_ProcessNode(Model, Scene->mRootNode, Scene); } @@ -117,7 +117,6 @@ void ERS_LEGACY_FUNCTION_IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* bool AlreadyHasTexture = false; for (unsigned long x = 0; x < Mesh->Loader_RequestedTextureInformation_.size(); x++) { if (Mesh->Loader_RequestedTextureInformation_[x].second == TextureIdentifier) { - SystemUtils_->Logger_->Log(std::string("Found Matching Texture '") + Mesh->Loader_RequestedTextureInformation_[x].second + "'", 3); AlreadyHasTexture = true; break; } diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h index fd486939b8..2382f50408 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.h @@ -44,21 +44,20 @@ - +/** + * @brief Loads mesh texture information for legacy model formats that don't have this already encoded in them. + * + * @param Metadata + * @param Model + * @param SystemUtils + * @param AssetID + * @param LogEnable + */ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_Model* Model, ERS_STRUCT_SystemUtils* SystemUtils, long AssetID, bool LogEnable); -/** - * @brief Load a texture given the id - * - * @param ID - * @param FlipTextures - * @return ERS_STRUCT_Texture - */ -ERS_STRUCT_Texture ERS_LEGACY_FUNCTION_LoadTexture(long ID, bool FlipTextures = false); - /** * @brief Populates Texture Request Information For The Mesh * @@ -67,16 +66,13 @@ ERS_STRUCT_Texture ERS_LEGACY_FUNCTION_LoadTexture(long ID, bool FlipTextures = */ void ERS_LEGACY_FUNCTION_IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh); - - - /** * @brief Function Used To Process Subnodes Of SceneFiles. * * @param Node * @param Scene */ -void ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene); +void ERS_LEGACY_FUNCTION_ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene); /** * @brief Process Meshes From Model. @@ -86,20 +82,4 @@ void ProcessNode(ERS_STRUCT_Model* Model, aiNode *Node, const aiScene *Scene); * @param Scene * @return ERS_STRUCT_Mesh */ -ERS_STRUCT_Mesh ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PerallocIndSize, aiMesh *Mesh, const aiScene *Scene); - - - - - - - - -/** - * @brief Creates texture pointers within the model's meshes - * - * @param Model - */ -void MatchTextures(ERS_STRUCT_Model* Model); - - +ERS_STRUCT_Mesh ERS_LEGACY_FUNCTION_ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PerallocIndSize, aiMesh *Mesh, const aiScene *Scene); \ No newline at end of file From 2163cf72eed53970291ea32c72e1aa13a4dbab6b Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:49:42 +0000 Subject: [PATCH 22/33] Implement New Model Format Loader --- .../ERS_FUNCTION_ModelMetadataDecoderManager.cpp | 2 ++ .../ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp index 95459e1805..4c12ab56aa 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.cpp @@ -18,9 +18,11 @@ bool ERS_FUNCTION_DecodeModelMetadata(YAML::Node Metadata, ERS_STRUCT_Model* Mod bool Status = false; if (FormatVersion == "0.0.0") { SystemUtils->Logger_->Log("Determined Model Metadata Version To Be '0.0.0', Attempting To Decode Model Metadata", 3, LogEnable); + ERS_FUNCTION_Legacy_PreprocessTextureInfo(Metadata, Model, SystemUtils, AssetID, LogEnable); Status = ERS_FUNCTION_DecodeModelMetadataV000(Metadata, Model, SystemUtils, AssetID, LogEnable); } else if (FormatVersion == "0.0.1") { SystemUtils->Logger_->Log("Determined Model Metadata Version To Be '0.0.1', Attempting To Decode Model Metadata", 3, LogEnable); + ERS_FUNCTION_Legacy_PreprocessTextureInfo(Metadata, Model, SystemUtils, AssetID, LogEnable); Status = ERS_FUNCTION_DecodeModelMetadataV001(Metadata, Model, SystemUtils, AssetID, LogEnable); } else if (FormatVersion == "0.0.2") { SystemUtils->Logger_->Log("Determined Model Metadata Version To Be '0.0.2', Attempting To Decode Model Metadata", 3, LogEnable); diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h index dd4587613e..c58d37dbe8 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_ModelMetadataDecoderManager.h @@ -18,6 +18,8 @@ #include #include +#include + #include #include #include From ba8e7fca77be0aa06abe9c618d7bc8e9fdab2b0f Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:53:33 +0000 Subject: [PATCH 23/33] Implement New Model Format Loader --- .../ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index 256d75ffa2..d668436a1d 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -7,11 +7,7 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_Model* Model, ERS_STRUCT_SystemUtils* SystemUtils, long AssetID, bool LogEnable) { - // Read Metadata From Asset - std::unique_ptr ModelMetadata = std::make_unique(); - SystemUtils->ERS_IOSubsystem_->ReadAsset(AssetID, ModelMetadata.get()); - std::string ModelMetadataString = std::string((const char*)ModelMetadata->Data.get()); - YAML::Node Metadata = YAML::Load(ModelMetadataString); + SystemUtils->Logger_->Log("Using Legacy Model Texture Identification", 4, LogEnable); // Read Mesh Assimp::Importer Importer; @@ -21,7 +17,7 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_M // Log Errors if (!Scene || Scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !Scene->mRootNode) { - SystemUtils_->Logger_->Log(std::string(std::string("Model Loading Error: ") + std::string(Importer.GetErrorString())).c_str(), 10); + SystemUtils->Logger_->Log(std::string(std::string("Model Loading Error: ") + std::string(Importer.GetErrorString())).c_str(), 10); Model->IsReadyForGPU = false; return; } From 670c3105aff27e5bc2122de3385f314e04fe03fb Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:57:49 +0000 Subject: [PATCH 24/33] Implement New Model Format Loader --- .../ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index d668436a1d..e990e1c347 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -12,7 +12,7 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_M // Read Mesh Assimp::Importer Importer; std::unique_ptr ModelData = std::make_unique(); - SystemUtils->ERS_IOSubsystem_->ReadAsset(Model->ModelDataID, ModelData.get()); + SystemUtils->ERS_IOSubsystem_->ReadAsset(Metadata["AssetID"].as(), ModelData.get()); const aiScene* Scene = Importer.ReadFileFromMemory(ModelData->Data.get(), (int)ModelData->Size_B, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices, ""); // Log Errors From d2c270ef76fff4d7fc3163ceda171be639804644 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:58:15 +0000 Subject: [PATCH 25/33] Implement New Model Format Loader --- .../ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index e990e1c347..efbf0b43aa 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -12,7 +12,7 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_M // Read Mesh Assimp::Importer Importer; std::unique_ptr ModelData = std::make_unique(); - SystemUtils->ERS_IOSubsystem_->ReadAsset(Metadata["AssetID"].as(), ModelData.get()); + SystemUtils->ERS_IOSubsystem_->ReadAsset(Metadata["AssetID"].as(), ModelData.get()); const aiScene* Scene = Importer.ReadFileFromMemory(ModelData->Data.get(), (int)ModelData->Size_B, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices, ""); // Log Errors From ad19e15f139be639164a429b4927297a4eb30403 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 06:59:45 +0000 Subject: [PATCH 26/33] Implement New Model Format Loader --- .../ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp index efbf0b43aa..db71586727 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_FUNCTION_Legacy_PreprocessTextureInfo.cpp @@ -12,7 +12,7 @@ void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_M // Read Mesh Assimp::Importer Importer; std::unique_ptr ModelData = std::make_unique(); - SystemUtils->ERS_IOSubsystem_->ReadAsset(Metadata["AssetID"].as(), ModelData.get()); + SystemUtils->ERS_IOSubsystem_->ReadAsset(Metadata["ModelID"].as(), ModelData.get()); const aiScene* Scene = Importer.ReadFileFromMemory(ModelData->Data.get(), (int)ModelData->Size_B, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices, ""); // Log Errors From a6edb27259e26b68720d216a2861f6db9850fc97 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 07:29:26 +0000 Subject: [PATCH 27/33] Implement New Model Format Loader --- .../Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp index 4b34035c76..d41b975685 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp @@ -58,7 +58,7 @@ void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* Ope Number = std::to_string(AmbientOcclusionHandle++); TypeID = 1; HasAmbientOcclusion = true; - } else if(Type == "texture_diffuse") { + } else if(Type == "texture_diffuse" || Type == "texture_base_color") { Number = std::to_string(DiffuseHandle++); TypeID = 2; HasDiffuse = true; From 56d34ecd9fb6479dcb8948efb534692d4a1782b9 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 07:34:30 +0000 Subject: [PATCH 28/33] Implement New Model Format Loader --- .../ERS_CLASS_ExternalModelLoader.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index 5adecfa020..91ce62f107 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -544,20 +544,3 @@ bool ERS_CLASS_ExternalModelLoader::LoadModel(std::string ModelPath, ERS_STRUCT_ } } - - - - //todo: - // then, add the modelwriter to "GUI_Window_ImportAsset" so it can proeprly export things - // then moake it write those models with this class (basically, have the importer load the model with this file, then write it with ERS_modelwriter) - // then make the importer class (in utils), have multithreading, and allow it to import a list of models (or something like that for batch importing) - // finally, add the new import button to import a batch of models and have it traverse the filesystem to find said models given a directory. - - - - - - - - - From 0c59ba69a21021324c52b407bdba2ac7ea41bc22 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 07:59:39 +0000 Subject: [PATCH 29/33] Implement New Model Format Loader --- .../ERS_CLASS_ExternalModelLoader.cpp | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index 91ce62f107..c42b1b21aa 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -315,29 +315,6 @@ void ERS_CLASS_ExternalModelLoader::ProcessNode(ERS_STRUCT_ModelWriterData &Data } -} -void ERS_CLASS_ExternalModelLoader::HandleMeshTextures(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial* Material, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh) { - - SystemUtils_->Logger_->Log("Identifying Mesh Textures", 3); - AddTexture(Data, Model, Material, aiTextureType_AMBIENT, "texture_ambient", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_AMBIENT_OCCLUSION, "texture_ambient_occlusion", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_BASE_COLOR, "texture_base_color", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_DIFFUSE, "texture_diffuse", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_DIFFUSE_ROUGHNESS, "texture_diffuse_roughness", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_DISPLACEMENT, "texture_displacement", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_EMISSION_COLOR, "texture_emission_color", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_EMISSIVE, "texture_emissive", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_HEIGHT, "texture_height", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_LIGHTMAP, "texture_lightmap", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_METALNESS, "texture_metalness", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_NORMAL_CAMERA, "texture_normal_camera", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_NORMALS, "texture_normals", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_OPACITY, "texture_opacity", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_REFLECTION, "texture_reflection", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_SHININESS, "texture_shininess", ModelDirectory, TargetMesh); - AddTexture(Data, Model, Material, aiTextureType_SPECULAR, "texture_specular", ModelDirectory, TargetMesh); - SystemUtils_->Logger_->Log("Finshed Mesh Texture Identification", 4); - } ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMesh *Mesh, const aiScene *Scene, std::string ModelDirectory) { @@ -413,6 +390,29 @@ ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWrite return OutputMesh; +} +void ERS_CLASS_ExternalModelLoader::HandleMeshTextures(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial* Material, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh) { + + SystemUtils_->Logger_->Log("Identifying Mesh Textures", 3); + AddTexture(Data, Model, Material, aiTextureType_AMBIENT, "texture_ambient", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_AMBIENT_OCCLUSION, "texture_ambient_occlusion", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_BASE_COLOR, "texture_base_color", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_DIFFUSE, "texture_diffuse", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_DIFFUSE_ROUGHNESS, "texture_diffuse_roughness", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_DISPLACEMENT, "texture_displacement", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_EMISSION_COLOR, "texture_emission_color", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_EMISSIVE, "texture_emissive", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_HEIGHT, "texture_height", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_LIGHTMAP, "texture_lightmap", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_METALNESS, "texture_metalness", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_NORMAL_CAMERA, "texture_normal_camera", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_NORMALS, "texture_normals", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_OPACITY, "texture_opacity", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_REFLECTION, "texture_reflection", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_SHININESS, "texture_shininess", ModelDirectory, TargetMesh); + AddTexture(Data, Model, Material, aiTextureType_SPECULAR, "texture_specular", ModelDirectory, TargetMesh); + SystemUtils_->Logger_->Log("Finshed Mesh Texture Identification", 4); + } void ERS_CLASS_ExternalModelLoader::AddTexture(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial *Mat, aiTextureType Type, std::string TypeName, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh) { From 7bf7a5a76df5b5adb2be45b9d7f52871e538b7b3 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 23:21:33 +0000 Subject: [PATCH 30/33] Implement New Model Format Loader --- .../ERS_CLASS_ExternalModelLoader.cpp | 79 ++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index c42b1b21aa..15d1cb524b 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -316,6 +316,76 @@ void ERS_CLASS_ExternalModelLoader::ProcessNode(ERS_STRUCT_ModelWriterData &Data } + + + + +void IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh) { + + std::vector> TextureTypes; + TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT, "texture_ambient")); + TextureTypes.push_back(std::make_pair(aiTextureType_AMBIENT_OCCLUSION, "texture_ambient_occlusion")); + TextureTypes.push_back(std::make_pair(aiTextureType_BASE_COLOR, "texture_base_color")); + TextureTypes.push_back(std::make_pair(aiTextureType_DIFFUSE, "texture_diffuse")); + TextureTypes.push_back(std::make_pair(aiTextureType_DIFFUSE_ROUGHNESS, "texture_diffuse_roughness")); + TextureTypes.push_back(std::make_pair(aiTextureType_DISPLACEMENT, "texture_displacement")); + TextureTypes.push_back(std::make_pair(aiTextureType_EMISSION_COLOR, "texture_emission_color")); + TextureTypes.push_back(std::make_pair(aiTextureType_EMISSIVE, "texture_emissive")); + TextureTypes.push_back(std::make_pair(aiTextureType_HEIGHT, "texture_height")); + TextureTypes.push_back(std::make_pair(aiTextureType_LIGHTMAP, "texture_lightmap")); + TextureTypes.push_back(std::make_pair(aiTextureType_METALNESS, "texture_metalness")); + TextureTypes.push_back(std::make_pair(aiTextureType_NONE, "texture_none")); + TextureTypes.push_back(std::make_pair(aiTextureType_NORMAL_CAMERA, "texture_normal_camera")); + TextureTypes.push_back(std::make_pair(aiTextureType_NORMALS, "texture_normals")); + TextureTypes.push_back(std::make_pair(aiTextureType_OPACITY, "texture_opacity")); + TextureTypes.push_back(std::make_pair(aiTextureType_REFLECTION, "texture_reflection")); + TextureTypes.push_back(std::make_pair(aiTextureType_SHININESS, "texture_shininess")); + TextureTypes.push_back(std::make_pair(aiTextureType_SPECULAR, "texture_specular")); + TextureTypes.push_back(std::make_pair(aiTextureType_UNKNOWN, "texture_unknown")); + + // Iterate Over All Texture Types + for (unsigned int TextureTypeIndex = 0; TextureTypeIndex < TextureTypes.size(); TextureTypeIndex++) { + + aiTextureType Type = TextureTypes[TextureTypeIndex].first; + std::string TypeName = TextureTypes[TextureTypeIndex].second; + + // Iterate Through Textures For This Type + for (unsigned int i=0; i< Mat->GetTextureCount(Type); i++) { + + + // Calculate Texture Path + aiString TextureString; + Mat->GetTexture(Type, i, &TextureString); + std::string TextureIdentifier = std::string(std::string(TextureString.C_Str())); + + //std::string Message = std::string("Model Requesting Texture Of Type '") + TypeName + std::string("' With Identifier '") + TextureIdentifier + std::string("'"); + //SystemUtils_->Logger_->Log(Message, 3); + + // Search Texture List For Index Of Same Match, Add To List Of Unique Textures If Not Found + bool AlreadyHasTexture = false; + for (unsigned long x = 0; x < Mesh->Loader_RequestedTextureInformation_.size(); x++) { + if (Mesh->Loader_RequestedTextureInformation_[x].second == TextureIdentifier) { + //SystemUtils_->Logger_->Log(std::string("Found Matching Texture '") + Mesh->Loader_RequestedTextureInformation_[x].second + "'", 3); + AlreadyHasTexture = true; + break; + } + } + + // If It's Not Already In The List, Add IT + if (!AlreadyHasTexture) { + Mesh->Loader_RequestedTextureInformation_.push_back(std::make_pair(TypeName, TextureIdentifier)); + } + + + } + + } + +} + + + + ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMesh *Mesh, const aiScene *Scene, std::string ModelDirectory) { // Create Data Holders @@ -323,7 +393,8 @@ ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWrite // Process Materials aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; - HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); + // HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); + IdentifyMeshTextures(Material, &OutputMesh); // Iterate Through Meshes' Vertices for (unsigned int i = 0; i < Mesh->mNumVertices; i++) { @@ -391,6 +462,12 @@ ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWrite return OutputMesh; } + + + + + + void ERS_CLASS_ExternalModelLoader::HandleMeshTextures(ERS_STRUCT_ModelWriterData &Data, ERS_STRUCT_Model* Model, aiMaterial* Material, std::string ModelDirectory, ERS_STRUCT_Mesh* TargetMesh) { SystemUtils_->Logger_->Log("Identifying Mesh Textures", 3); From ed5f90611761db16bdd3b34d7c8c0ca965646f2a Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 23:23:54 +0000 Subject: [PATCH 31/33] Implement New Model Format Loader --- .../ERS_CLASS_ExternalModelLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index 15d1cb524b..543285630b 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -393,8 +393,8 @@ ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWrite // Process Materials aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; - // HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); - IdentifyMeshTextures(Material, &OutputMesh); + HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); + // IdentifyMeshTextures(Material, &OutputMesh); // Iterate Through Meshes' Vertices for (unsigned int i = 0; i < Mesh->mNumVertices; i++) { From 75aafbacc37d4f35e340e3d12cd9259218079329 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 23:47:31 +0000 Subject: [PATCH 32/33] Implement New Model Format Loader --- .../ERS_CLASS_ExternalModelLoader.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index 543285630b..93d1d5eaf5 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -393,8 +393,8 @@ ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWrite // Process Materials aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; - HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); - // IdentifyMeshTextures(Material, &OutputMesh); + // HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); + IdentifyMeshTextures(Material, &OutputMesh); // Iterate Through Meshes' Vertices for (unsigned int i = 0; i < Mesh->mNumVertices; i++) { @@ -506,8 +506,8 @@ void ERS_CLASS_ExternalModelLoader::AddTexture(ERS_STRUCT_ModelWriterData &Data, if (std::find(Data.TextureList.begin(), Data.TextureList.end(), FilePath) == Data.TextureList.end()) { Data.TextureList.push_back(FilePath); Data.TextureNames.push_back(Str.C_Str()); - TargetMesh->Loader_RequestedTextureInformation_.push_back(std::make_pair(TypeName, Str.C_Str())); } + TargetMesh->Loader_RequestedTextureInformation_.push_back(std::make_pair(TypeName, Str.C_Str())); } From a9ca895c3c6bcc7328a1a92510835e20ea348e40 Mon Sep 17 00:00:00 2001 From: datacrystals Date: Mon, 12 Sep 2022 23:48:30 +0000 Subject: [PATCH 33/33] Implement New Model Format Loader --- .../ERS_CLASS_ExternalModelLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index 93d1d5eaf5..6bc93e1615 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -393,8 +393,8 @@ ERS_STRUCT_Mesh ERS_CLASS_ExternalModelLoader::ProcessMesh(ERS_STRUCT_ModelWrite // Process Materials aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex]; - // HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); - IdentifyMeshTextures(Material, &OutputMesh); + HandleMeshTextures(Data, Model, Material, ModelDirectory, &OutputMesh); + // IdentifyMeshTextures(Material, &OutputMesh); // Iterate Through Meshes' Vertices for (unsigned int i = 0; i < Mesh->mNumVertices; i++) {