Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

369 update internal model format #370

Merged
merged 33 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
34b01ec
Implement New Model Format Writer
datacrystals Sep 12, 2022
4a87050
Implement New Model Format Writer
datacrystals Sep 12, 2022
b253812
Implement New Model Format Writer
datacrystals Sep 12, 2022
1437dee
Implement New Model Format Writer
datacrystals Sep 12, 2022
a21979b
Implement New Model Format Writer
datacrystals Sep 12, 2022
91619d5
Implement New Model Format Writer
datacrystals Sep 12, 2022
0a6b78a
Implement New Model Format Loader
datacrystals Sep 12, 2022
d383d06
Implement New Model Format Loader
datacrystals Sep 12, 2022
34b3308
Implement New Model Format Loader
datacrystals Sep 12, 2022
ef5bd93
Implement New Model Format Loader
datacrystals Sep 12, 2022
bdda875
Implement New Model Format Loader
datacrystals Sep 12, 2022
d157294
Implement New Model Format Loader
datacrystals Sep 12, 2022
285c076
Implement New Model Format Loader
datacrystals Sep 12, 2022
9c754d7
Implement New Model Format Loader
datacrystals Sep 12, 2022
7f718c6
Implement New Model Format Loader
datacrystals Sep 12, 2022
276dfff
Implement New Model Format Loader
datacrystals Sep 12, 2022
9eb2316
Implement New Model Format Loader
datacrystals Sep 12, 2022
a33ba22
Implement New Model Format Loader
datacrystals Sep 12, 2022
217f6d0
Implement New Model Format Loader
datacrystals Sep 12, 2022
c105325
Implement New Model Format Loader
datacrystals Sep 12, 2022
b2984d3
Implement New Model Format Loader
datacrystals Sep 12, 2022
2163cf7
Implement New Model Format Loader
datacrystals Sep 12, 2022
ba8e7fc
Implement New Model Format Loader
datacrystals Sep 12, 2022
670c310
Implement New Model Format Loader
datacrystals Sep 12, 2022
d2c270e
Implement New Model Format Loader
datacrystals Sep 12, 2022
ad19e15
Implement New Model Format Loader
datacrystals Sep 12, 2022
a6edb27
Implement New Model Format Loader
datacrystals Sep 12, 2022
56d34ec
Implement New Model Format Loader
datacrystals Sep 12, 2022
0c59ba6
Implement New Model Format Loader
datacrystals Sep 12, 2022
7bf7a5a
Implement New Model Format Loader
datacrystals Sep 12, 2022
ed5f906
Implement New Model Format Loader
datacrystals Sep 12, 2022
75aafba
Implement New Model Format Loader
datacrystals Sep 12, 2022
a9ca895
Implement New Model Format Loader
datacrystals Sep 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Source/Core/Loader/ERS_ModelLoader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ 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"
"ERS_FUNCTION_ModelMetadataDecoderManager.cpp"

# Add Header Files (.h)
"ERS_CLASS_ModelLoader.h"
"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"
"ERS_FUNCTION_ModelMetadataDecoderManager.h"


Expand Down
59 changes: 31 additions & 28 deletions Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,12 @@ 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
);

}
Expand All @@ -495,6 +493,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);
Expand Down Expand Up @@ -563,38 +563,41 @@ 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
Model->Meshes[Model->NumMeshes_] = OutputMesh;
Model->NumMeshes_++;

return OutputMesh;

}

void ERS_CLASS_ModelLoader::IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh) {

std::vector<std::pair<aiTextureType, std::string>> 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++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//======================================================================//
// This file is part of the BrainGenix-ERS Environment Rendering System //
//======================================================================//

#include <ERS_FUNCTION_Legacy_PreprocessTextureInfo.h>


void ERS_FUNCTION_Legacy_PreprocessTextureInfo(YAML::Node Metadata, ERS_STRUCT_Model* Model, ERS_STRUCT_SystemUtils* SystemUtils, long AssetID, bool LogEnable) {

SystemUtils->Logger_->Log("Using Legacy Model Texture Identification", 4, LogEnable);

// Read Mesh
Assimp::Importer Importer;
std::unique_ptr<ERS_STRUCT_IOData> ModelData = std::make_unique<ERS_STRUCT_IOData>();
SystemUtils->ERS_IOSubsystem_->ReadAsset(Metadata["ModelID"].as<long>(), 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
ERS_LEGACY_FUNCTION_ProcessNode(Model, Scene->mRootNode, 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(
ERS_LEGACY_FUNCTION_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++) {
ERS_LEGACY_FUNCTION_ProcessNode(Model, Node->mChildren[i], 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];
ERS_LEGACY_FUNCTION_IdentifyMeshTextures(Material, &OutputMesh);


// Return Populated Mesh
return OutputMesh;

}

void ERS_LEGACY_FUNCTION_IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh) {

std::vector<std::pair<aiTextureType, std::string>> 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()));

// 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) {
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));
}


}

}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//======================================================================//
// This file is part of the BrainGenix-ERS Environment Rendering System //
//======================================================================//

#pragma once

// Standard Libraries (BG convention: use <> instead of "")
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <future>
#include <thread>
#include <chrono>

// Third-Party Libraries (BG convention: use <> instead of "")
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include <FreeImage.h>

#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>


// Internal Libraries (BG convention: use <> instead of "")
#include <ERS_STRUCT_Mesh.h>
#include <ERS_STRUCT_Texture.h>
#include <ERS_STRUCT_Vertex.h>
#include <ERS_STRUCT_Model.h>

#include <ERS_STRUCT_SystemUtils.h>






/**
* @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 Populates Texture Request Information For The Mesh
*
* @param Mat
* @param Mesh
*/
void ERS_LEGACY_FUNCTION_IdentifyMeshTextures(aiMaterial* Mat, ERS_STRUCT_Mesh* Mesh);

/**
* @brief Function Used To Process Subnodes Of SceneFiles.
*
* @param Node
* @param Scene
*/
void ERS_LEGACY_FUNCTION_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 ERS_LEGACY_FUNCTION_ProcessMesh(ERS_STRUCT_Model* Model, unsigned long PreallocVertSize, unsigned long PerallocIndSize, aiMesh *Mesh, const aiScene *Scene);
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ 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);
Status = ERS_FUNCTION_DecodeModelMetadataV002(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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#include <ERS_STRUCT_TextureLevel.h>
#include <ERS_STRUCT_Texture.h>

#include <ERS_FUNCTION_Legacy_PreprocessTextureInfo.h>

#include <ERS_FUNCTION_ModelMetadataDecoderV0.0.0.h>
#include <ERS_FUNCTION_ModelMetadataDecoderV0.0.1.h>
#include <ERS_FUNCTION_ModelMetadataDecoderV0.0.2.h>


/**
Expand Down
Loading