From d44641398fff18f151d5f7d986736b7d5b0450d5 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 26 Dec 2021 11:16:02 +0100 Subject: [PATCH] Add console progresshandler --- code/Common/DefaultProgressHandler.h | 17 ++++++++------- code/Common/Importer.cpp | 2 +- include/assimp/ProgressHandler.hpp | 1 + tools/assimp_cmd/Main.cpp | 31 ++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/code/Common/DefaultProgressHandler.h b/code/Common/DefaultProgressHandler.h index 4626204af..ebf4a0e74 100644 --- a/code/Common/DefaultProgressHandler.h +++ b/code/Common/DefaultProgressHandler.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -48,18 +47,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -namespace Assimp { +namespace Assimp { // ------------------------------------------------------------------------------------ -/** @brief Internal default implementation of the #ProgressHandler interface. */ +/** + * @brief Internal default implementation of the #ProgressHandler interface. + */ class DefaultProgressHandler : public ProgressHandler { - - virtual bool Update(float /*percentage*/) { +public: + /// @brief Ignores the update callback. + bool Update(float) override { return false; } +}; - -}; // !class DefaultProgressHandler } // Namespace Assimp -#endif +#endif // INCLUDED_AI_DEFAULTPROGRESSHANDLER_H diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index 41b73fd12..2f9c23bec 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -329,7 +329,7 @@ bool Importer::IsDefaultIOHandler() const { // ------------------------------------------------------------------------------------------------ // Supplies a custom progress handler to get regular callbacks during importing -void Importer::SetProgressHandler ( ProgressHandler* pHandler ) { +void Importer::SetProgressHandler(ProgressHandler* pHandler) { ai_assert(nullptr != pimpl); ASSIMP_BEGIN_EXCEPTION_REGION(); diff --git a/include/assimp/ProgressHandler.hpp b/include/assimp/ProgressHandler.hpp index a42015400..40661fba8 100644 --- a/include/assimp/ProgressHandler.hpp +++ b/include/assimp/ProgressHandler.hpp @@ -74,6 +74,7 @@ protected: public: /// @brief Virtual destructor. virtual ~ProgressHandler () { + // empty } // ------------------------------------------------------------------- diff --git a/tools/assimp_cmd/Main.cpp b/tools/assimp_cmd/Main.cpp index 8d76e1f5e..87467579f 100644 --- a/tools/assimp_cmd/Main.cpp +++ b/tools/assimp_cmd/Main.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -47,6 +45,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Main.h" +#include +#include + +class ConsoleProgressHandler : public ProgressHandler { +public: + ConsoleProgressHandler() : + ProgressHandler() { + // empty + } + + ~ConsoleProgressHandler() override { + // empty + } + + bool Update(float percentage) override { + std::cout << percentage * 100.0f << " %\n"; + return true; + } +}; const char* AICMD_MSG_ABOUT = "------------------------------------------------------ \n" "Open Asset Import Library (\"Assimp\", https://github.com/assimp/assimp) \n" @@ -73,10 +90,10 @@ const char* AICMD_MSG_HELP = "\n Use \'assimp --help\' for detailed help on a command.\n" ; -/*extern*/ Assimp::Importer* globalImporter = NULL; +/*extern*/ Assimp::Importer* globalImporter = nullptr; #ifndef ASSIMP_BUILD_NO_EXPORT -/*extern*/ Assimp::Exporter* globalExporter = NULL; +/*extern*/ Assimp::Exporter* globalExporter = nullptr; #endif // ------------------------------------------------------------------------------ @@ -286,6 +303,9 @@ const aiScene* ImportModel( // do the actual import, measure time const clock_t first = clock(); + ConsoleProgressHandler *ph = new ConsoleProgressHandler; + globalImporter->SetProgressHandler(ph); + const aiScene* scene = globalImporter->ReadFile(path,imp.ppFlags); if (imp.showLog) { @@ -305,6 +325,9 @@ const aiScene* ImportModel( if (imp.log) { FreeLogStreams(); } + globalImporter->SetProgressHandler(nullptr); + delete ph; + return scene; }