From 6be0ce1ec93a373a1c0f8cf3ab1499e906560fb1 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Thu, 14 May 2020 17:43:31 +0100 Subject: [PATCH] Initial pass at adding logging --- code/AssetLib/FBX/FBXBinaryTokenizer.cpp | 5 ++- code/AssetLib/FBX/FBXCompileConfig.h | 6 +++ code/AssetLib/FBX/FBXConverter.h | 2 +- code/AssetLib/FBX/FBXDocument.cpp | 5 +++ code/AssetLib/FBX/FBXImporter.cpp | 2 + code/AssetLib/FBX/FBXParser.cpp | 2 + code/AssetLib/FBX/FBXTokenizer.cpp | 4 +- code/AssetLib/glTF2/glTF2Importer.cpp | 33 +++++++++++---- include/assimp/Logger.hpp | 52 ++++++++++++------------ 9 files changed, 72 insertions(+), 39 deletions(-) diff --git a/code/AssetLib/FBX/FBXBinaryTokenizer.cpp b/code/AssetLib/FBX/FBXBinaryTokenizer.cpp index 7faa0518b..dd84196f1 100644 --- a/code/AssetLib/FBX/FBXBinaryTokenizer.cpp +++ b/code/AssetLib/FBX/FBXBinaryTokenizer.cpp @@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace Assimp { namespace FBX { @@ -426,7 +427,8 @@ bool ReadScope(TokenList& output_tokens, const char* input, const char*& cursor, // TODO: Test FBX Binary files newer than the 7500 version to check if the 64 bits address behaviour is consistent void TokenizeBinary(TokenList& output_tokens, const char* input, size_t length) { - ai_assert(input); + ai_assert(input); + ASSIMP_FBX_LOG_DEBUG("Tokenizing binary FBX file"); if(length < 0x1b) { TokenizeError("file is too short",0); @@ -451,6 +453,7 @@ void TokenizeBinary(TokenList& output_tokens, const char* input, size_t length) /*Result ignored*/ ReadByte(input, cursor, input + length); /*Result ignored*/ ReadByte(input, cursor, input + length); const uint32_t version = ReadWord(input, cursor, input + length); + ASSIMP_FBX_LOG_DEBUG_F("FBX version: ", version); const bool is64bits = version >= 7500; const char *end = input + length; while (cursor < end ) { diff --git a/code/AssetLib/FBX/FBXCompileConfig.h b/code/AssetLib/FBX/FBXCompileConfig.h index 5cdaa6960..31c8a5fdd 100644 --- a/code/AssetLib/FBX/FBXCompileConfig.h +++ b/code/AssetLib/FBX/FBXCompileConfig.h @@ -75,4 +75,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # endif #endif +#ifndef ASSIMP_FBX_LOG_DEBUG +// These require the DefaultLogger header. +#define ASSIMP_FBX_LOG_DEBUG ASSIMP_LOG_DEBUG +#define ASSIMP_FBX_LOG_DEBUG_F ASSIMP_LOG_DEBUG_F +#endif + #endif // INCLUDED_AI_FBX_COMPILECONFIG_H diff --git a/code/AssetLib/FBX/FBXConverter.h b/code/AssetLib/FBX/FBXConverter.h index d4f75820f..c24434c34 100644 --- a/code/AssetLib/FBX/FBXConverter.h +++ b/code/AssetLib/FBX/FBXConverter.h @@ -412,7 +412,7 @@ private: // ------------------------------------------------------------------------------------------------ // FBX file could have embedded textures not connected to anything - void ConvertOrphantEmbeddedTextures(); + void ConvertOrphanedEmbeddedTextures(); private: // 0: not assigned yet, others: index is value - 1 diff --git a/code/AssetLib/FBX/FBXDocument.cpp b/code/AssetLib/FBX/FBXDocument.cpp index 5940f3cfa..063ad677c 100644 --- a/code/AssetLib/FBX/FBXDocument.cpp +++ b/code/AssetLib/FBX/FBXDocument.cpp @@ -55,6 +55,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FBXDocumentUtil.h" #include "FBXProperties.h" +#include + #include #include #include @@ -264,6 +266,8 @@ Document::Document(const Parser& parser, const ImportSettings& settings) : settings(settings) , parser(parser) { + ASSIMP_FBX_LOG_DEBUG("Creating FBX Document"); + // Cannot use array default initialization syntax because vc8 fails on it for (auto &timeStamp : creationTimeStamp) { timeStamp = 0; @@ -308,6 +312,7 @@ void Document::ReadHeader() { const Scope& shead = *ehead->Compound(); fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0)); + ASSIMP_FBX_LOG_DEBUG_F("FBX Version: ", fbxVersion); // While we may have some success with newer files, we don't support // the older 6.n fbx format diff --git a/code/AssetLib/FBX/FBXImporter.cpp b/code/AssetLib/FBX/FBXImporter.cpp index 11c1503d8..232f78c13 100644 --- a/code/AssetLib/FBX/FBXImporter.cpp +++ b/code/AssetLib/FBX/FBXImporter.cpp @@ -146,6 +146,8 @@ void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy ThrowException("Could not open file for reading"); } + ASSIMP_FBX_LOG_DEBUG("Reading FBX file"); + // read entire file into memory - no streaming for this, fbx // files can grow large, but the assimp output data structure // then becomes very large, too. Assimp doesn't support diff --git a/code/AssetLib/FBX/FBXParser.cpp b/code/AssetLib/FBX/FBXParser.cpp index aef59d60c..04c58f70c 100644 --- a/code/AssetLib/FBX/FBXParser.cpp +++ b/code/AssetLib/FBX/FBXParser.cpp @@ -59,6 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include @@ -220,6 +221,7 @@ Parser::Parser (const TokenList& tokens, bool is_binary) , cursor(tokens.begin()) , is_binary(is_binary) { + ASSIMP_FBX_LOG_DEBUG("Parsing FBX tokens"); root.reset(new Scope(*this,true)); } diff --git a/code/AssetLib/FBX/FBXTokenizer.cpp b/code/AssetLib/FBX/FBXTokenizer.cpp index 831c40061..1fe39a175 100644 --- a/code/AssetLib/FBX/FBXTokenizer.cpp +++ b/code/AssetLib/FBX/FBXTokenizer.cpp @@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FBXTokenizer.h" #include "FBXUtil.h" #include +#include namespace Assimp { namespace FBX { @@ -134,7 +135,8 @@ void ProcessDataToken( TokenList& output_tokens, const char*& start, const char* // ------------------------------------------------------------------------------------------------ void Tokenize(TokenList& output_tokens, const char* input) { - ai_assert(input); + ai_assert(input); + ASSIMP_FBX_LOG_DEBUG("Tokenizing ascii FBX file"); // line and column numbers numbers are one-based unsigned int line = 1; diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index 10d0bc83b..ee6a1b298 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -286,6 +286,7 @@ static aiMaterial *ImportMaterial(std::vector &embeddedTexIdxs, Asset &r, M void glTF2Importer::ImportMaterials(glTF2::Asset &r) { const unsigned int numImportedMaterials = unsigned(r.materials.Size()); + ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numImportedMaterials, " materials"); Material defaultMaterial; mScene->mNumMaterials = numImportedMaterials + 1; @@ -333,6 +334,7 @@ static inline bool CheckValidFacesIndices(aiFace *faces, unsigned nFaces, unsign #endif // ASSIMP_BUILD_DEBUG void glTF2Importer::ImportMeshes(glTF2::Asset &r) { + ASSIMP_GLTF_LOG_DEBUG_F("Importing ", r.meshes.Size(), " meshes"); std::vector meshes; unsigned int k = 0; @@ -662,10 +664,12 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) { void glTF2Importer::ImportCameras(glTF2::Asset &r) { if (!r.cameras.Size()) return; - mScene->mNumCameras = r.cameras.Size(); - mScene->mCameras = new aiCamera *[r.cameras.Size()]; + const unsigned int numCameras = r.cameras.Size(); + ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numCameras, " cameras"); + mScene->mNumCameras = numCameras; + mScene->mCameras = new aiCamera *[numCameras]; - for (size_t i = 0; i < r.cameras.Size(); ++i) { + for (size_t i = 0; i < numCameras; ++i) { Camera &cam = r.cameras[i]; aiCamera *aicam = mScene->mCameras[i] = new aiCamera(); @@ -696,10 +700,12 @@ void glTF2Importer::ImportLights(glTF2::Asset &r) { if (!r.lights.Size()) return; - mScene->mNumLights = r.lights.Size(); - mScene->mLights = new aiLight *[r.lights.Size()]; + const unsigned int numLights = r.lights.Size(); + ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numLights, " lights"); + mScene->mNumLights = numLights; + mScene->mLights = new aiLight *[numLights]; - for (size_t i = 0; i < r.lights.Size(); ++i) { + for (size_t i = 0; i < numLights; ++i) { Light &light = r.lights[i]; aiLight *ail = mScene->mLights[i] = new aiLight(); @@ -958,6 +964,7 @@ void glTF2Importer::ImportNodes(glTF2::Asset &r) { if (!r.scene) { throw DeadlyImportError("GLTF: No scene"); } + ASSIMP_GLTF_LOG_DEBUG("Importing nodes"); std::vector> rootNodes = r.scene->nodes; @@ -1137,13 +1144,15 @@ std::unordered_map GatherSamplers(Animation &an void glTF2Importer::ImportAnimations(glTF2::Asset &r) { if (!r.scene) return; - mScene->mNumAnimations = r.animations.Size(); + const unsigned numAnimations = r.animations.Size(); + ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numAnimations, " animations"); + mScene->mNumAnimations = numAnimations; if (mScene->mNumAnimations == 0) { return; } - mScene->mAnimations = new aiAnimation *[mScene->mNumAnimations]; - for (unsigned int i = 0; i < r.animations.Size(); ++i) { + mScene->mAnimations = new aiAnimation *[numAnimations]; + for (unsigned int i = 0; i < numAnimations; ++i) { Animation &anim = r.animations[i]; aiAnimation *ai_anim = new aiAnimation(); @@ -1249,6 +1258,8 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) { if (numEmbeddedTexs == 0) return; + ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numEmbeddedTexs, " embedded textures"); + mScene->mTextures = new aiTexture *[numEmbeddedTexs]; // Add the embedded textures @@ -1288,6 +1299,7 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) { } void glTF2Importer::ImportCommonMetadata(glTF2::Asset& a) { + ASSIMP_GLTF_LOG_DEBUG("Importing metadata"); ai_assert(mScene->mMetaData == nullptr); const bool hasVersion = !a.asset.version.empty(); const bool hasGenerator = !a.asset.generator.empty(); @@ -1307,6 +1319,9 @@ void glTF2Importer::ImportCommonMetadata(glTF2::Asset& a) { } void glTF2Importer::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { + + ASSIMP_GLTF_LOG_DEBUG("Reading GLTF file"); + // clean all member arrays meshOffsets.clear(); embeddedTexIdxs.clear(); diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index a0b798564..f32c3edc2 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -273,33 +273,31 @@ void Logger::info(const std::string &message) { return info(message.c_str()); } -// ------------------------------------------------------------------------------------------------ -#define ASSIMP_LOG_WARN_F(string,...)\ - DefaultLogger::get()->warn((Formatter::format(string),__VA_ARGS__)) - -#define ASSIMP_LOG_ERROR_F(string,...)\ - DefaultLogger::get()->error((Formatter::format(string),__VA_ARGS__)) - -#define ASSIMP_LOG_DEBUG_F(string,...)\ - DefaultLogger::get()->debug((Formatter::format(string),__VA_ARGS__)) - -#define ASSIMP_LOG_INFO_F(string,...)\ - DefaultLogger::get()->info((Formatter::format(string),__VA_ARGS__)) - - -#define ASSIMP_LOG_WARN(string)\ - DefaultLogger::get()->warn(string) - -#define ASSIMP_LOG_ERROR(string)\ - DefaultLogger::get()->error(string) - -#define ASSIMP_LOG_DEBUG(string)\ - DefaultLogger::get()->debug(string) - -#define ASSIMP_LOG_INFO(string)\ - DefaultLogger::get()->info(string) - - } // Namespace Assimp +// ------------------------------------------------------------------------------------------------ +#define ASSIMP_LOG_WARN_F(string, ...) \ + Assimp::DefaultLogger::get()->warn((Assimp::Formatter::format(string), __VA_ARGS__)) + +#define ASSIMP_LOG_ERROR_F(string, ...) \ + Assimp::DefaultLogger::get()->error((Assimp::Formatter::format(string), __VA_ARGS__)) + +#define ASSIMP_LOG_DEBUG_F(string, ...) \ + Assimp::DefaultLogger::get()->debug((Assimp::Formatter::format(string), __VA_ARGS__)) + +#define ASSIMP_LOG_INFO_F(string, ...) \ + Assimp::DefaultLogger::get()->info((Assimp::Formatter::format(string), __VA_ARGS__)) + +#define ASSIMP_LOG_WARN(string) \ + Assimp::DefaultLogger::get()->warn(string) + +#define ASSIMP_LOG_ERROR(string) \ + Assimp::DefaultLogger::get()->error(string) + +#define ASSIMP_LOG_DEBUG(string) \ + Assimp::DefaultLogger::get()->debug(string) + +#define ASSIMP_LOG_INFO(string) \ + Assimp::DefaultLogger::get()->info(string) + #endif // !! INCLUDED_AI_LOGGER_H