1 #include <IO/AssimpLoader/AssimpFileLoader.hpp>
3 #include <Core/Asset/FileData.hpp>
4 #include <Core/Utils/StringUtils.hpp>
6 #include <assimp/postprocess.h>
7 #include <assimp/scene.h>
9 #include <IO/AssimpLoader/AssimpAnimationDataLoader.hpp>
10 #include <IO/AssimpLoader/AssimpCameraDataLoader.hpp>
11 #include <IO/AssimpLoader/AssimpGeometryDataLoader.hpp>
12 #include <IO/AssimpLoader/AssimpHandleDataLoader.hpp>
13 #include <IO/AssimpLoader/AssimpLightDataLoader.hpp>
20 using namespace Core::Utils;
21 using namespace Core::Asset;
23 AssimpFileLoader::AssimpFileLoader() =
default;
25 AssimpFileLoader::~AssimpFileLoader() =
default;
27 std::vector<std::string> AssimpFileLoader::getFileExtensions()
const {
28 std::string extensionsList;
30 m_importer.GetExtensionList( extensionsList );
33 std::istringstream iss( extensionsList );
35 std::vector<std::string> extensions;
36 while ( std::getline( iss, ext,
';' ) ) {
37 extensions.push_back( ext );
42 bool AssimpFileLoader::handleFileExtension(
const std::string& extension )
const {
43 return m_importer.IsExtensionSupported( extension );
46 FileData* AssimpFileLoader::loadFile(
const std::string& filename ) {
48 auto fileData =
new FileData( filename );
51 if ( !fileData->isInitialized() ) {
return nullptr; }
56 const aiScene* scene =
57 m_importer.ReadFile( fileData->getFileName(),
58 aiProcess_GenSmoothNormals | aiProcess_SortByPType |
59 aiProcess_CalcTangentSpace | aiProcess_GenUVCoords );
61 if ( scene ==
nullptr ) {
62 LOG( logINFO ) <<
"File \"" << fileData->getFileName()
63 <<
"\" assimp error : " << m_importer.GetErrorString() <<
".";
67 if ( fileData->isVerbose() ) { LOG( logINFO ) <<
"File Loading begin..."; }
69 std::clock_t startTime;
70 startTime = std::clock();
75 if ( scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE ) {
77 <<
" ai scene is incomplete, just try to load lights or skeletons (but not both).";
79 AssimpLightDataLoader lightLoader( Core::Utils::getDirName( filename ),
80 fileData->isVerbose() );
81 lightLoader.loadData( scene, fileData->m_lightData );
83 if ( !fileData->hasLight() ) {
84 AssimpHandleDataLoader handleLoader( fileData->isVerbose() );
85 handleLoader.loadData( scene, fileData->m_handleData );
87 AssimpAnimationDataLoader animationLoader( fileData->isVerbose() );
88 animationLoader.loadData( scene, fileData->m_animationData );
92 AssimpGeometryDataLoader geometryLoader( Core::Utils::getDirName( filename ),
93 fileData->isVerbose() );
94 geometryLoader.loadData( scene, fileData->m_geometryData );
100 bool ok = std::any_of( fileData->m_geometryData.begin(),
101 fileData->m_geometryData.end(),
102 [](
const auto& geom ) ->
bool { return geom->hasFaces(); } );
104 if ( fileData->isVerbose() ) { LOG( logINFO ) <<
"Point-cloud found. Aborting"; }
109 AssimpHandleDataLoader handleLoader( fileData->isVerbose() );
110 handleLoader.loadData( scene, fileData->m_handleData );
112 AssimpAnimationDataLoader animationLoader( fileData->isVerbose() );
113 animationLoader.loadData( scene, fileData->m_animationData );
115 AssimpLightDataLoader lightLoader( Core::Utils::getDirName( filename ),
116 fileData->isVerbose() );
117 lightLoader.loadData( scene, fileData->m_lightData );
118 AssimpCameraDataLoader cameraLoader( fileData->isVerbose() );
119 cameraLoader.loadData( scene, fileData->m_cameraData );
122 fileData->m_loadingTime = ( std::clock() - startTime ) / Scalar( CLOCKS_PER_SEC );
124 if ( fileData->isVerbose() ) {
125 LOG( logINFO ) <<
"File Loading end.";
127 fileData->displayInfo();
130 fileData->m_processed =
true;
135 std::string AssimpFileLoader::name()
const {