浏览代码

Merge branch 'master' into fix-fbx-metalness-import

Vyacheslav Vanin 3 年之前
父节点
当前提交
2da06dd41a

+ 1 - 1
CMakeLists.txt

@@ -56,7 +56,7 @@ IF(ASSIMP_HUNTER_ENABLED)
   add_definitions(-DASSIMP_USE_HUNTER)
 ENDIF()
 
-PROJECT(Assimp VERSION 5.1.3)
+PROJECT(Assimp VERSION 5.1.4)
 
 # All supported options ###############################################
 

+ 5 - 0
code/AssetLib/LWS/LWSLoader.cpp

@@ -537,6 +537,11 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
 
     // get file format version and print to log
     ++it;
+    
+    if ((*it).tokens[0].empty()) {
+        ASSIMP_LOG_ERROR("Invalid LWS file detectedm abort import.");
+        return;
+    }
     unsigned int version = strtoul10((*it).tokens[0].c_str());
     ASSIMP_LOG_INFO("LWS file format version is ", (*it).tokens[0]);
     first = 0.;

+ 6 - 2
code/AssetLib/MDL/MDLMaterialLoader.cpp

@@ -463,8 +463,12 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
             ASSIMP_LOG_WARN("Found a reference to an embedded DDS texture, "
                             "but texture height is not equal to 1, which is not supported by MED");
         }
-
-        pcNew.reset(new aiTexture());
+        if (iWidth == 0) {
+            ASSIMP_LOG_ERROR("Found a reference to an embedded DDS texture, but texture width is zero, aborting import.");
+            return;
+        }
+        
+        pcNew.reset(new aiTexture);
         pcNew->mHeight = 0;
         pcNew->mWidth = iWidth;
 

+ 2 - 2
code/AssetLib/X3D/X3DImporter.cpp

@@ -480,6 +480,6 @@ void X3DImporter::ParseHelper_Node_Exit() {
     }
 }
 
-#endif // !ASSIMP_BUILD_NO_X3D_IMPORTER
-
 } // namespace Assimp
+
+#endif // !ASSIMP_BUILD_NO_X3D_IMPORTER

+ 5 - 1
code/Common/BaseImporter.cpp

@@ -65,6 +65,7 @@ using namespace Assimp;
 // Constructor to be privately used by Importer
 BaseImporter::BaseImporter() AI_NO_EXCEPT
         : m_progress() {
+    // empty
 }
 
 // ------------------------------------------------------------------------------------------------
@@ -372,7 +373,10 @@ void BaseImporter::ConvertToUTF8(std::vector<char> &data) {
 
     // UTF 16 BE with BOM
     if (*((uint16_t *)&data.front()) == 0xFFFE) {
-
+        // Check to ensure no overflow can happen
+        if(data.size() % 2 != 0) {
+            return;
+        }
         // swap the endianness ..
         for (uint16_t *p = (uint16_t *)&data.front(), *end = (uint16_t *)&data.back(); p <= end; ++p) {
             ByteSwap::Swap2(p);

+ 9 - 8
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 <assimp/ProgressHandler.hpp>
 
-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

+ 1 - 1
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();

+ 1 - 0
include/assimp/ProgressHandler.hpp

@@ -74,6 +74,7 @@ protected:
 public:
     /// @brief  Virtual destructor.
     virtual ~ProgressHandler () {
+        // empty
     }
 
     // -------------------------------------------------------------------

+ 0 - 0
test/models/3DS/IMAGE1.bmp → test/models/3DS/IMAGE1.jpg


二进制
test/models/3DS/test1.3ds


+ 27 - 4
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 <assimp/ProgressHandler.hpp>
+#include <iostream>
+
+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 <verb> --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;
 }