From 59f732e10d23df3104b161c66efcde3805dade4e Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Thu, 20 Jun 2019 16:30:52 +0100 Subject: [PATCH 01/10] DAE Import: Don't use SkipElement() to skip empty Text IrrXML doesn't recognise the construction: `` as being an empty element, and so ColladaParser::TestTextContent advances the element stream into the `` element. Use TestClosing(const char*) instead of SkipElement() to skip an empty text element. --- code/Collada/ColladaParser.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code/Collada/ColladaParser.cpp b/code/Collada/ColladaParser.cpp index 2106bf01c..860ae2ae9 100644 --- a/code/Collada/ColladaParser.cpp +++ b/code/Collada/ColladaParser.cpp @@ -323,10 +323,8 @@ void ColladaParser::ReadMetaDataItem(StringMetaData &metadata) aiString aistr; aistr.Set(value_char); metadata.emplace(camel_key_str, aistr); - TestClosing(key_str.c_str()); } - else - SkipElement(); + TestClosing(key_str.c_str()); } else SkipElement(); From bf252c4452b76f9318b56d8c91f515bc13412a9c Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Thu, 20 Jun 2019 18:11:11 +0100 Subject: [PATCH 02/10] Add configuration of text format precision Define ASSIMP_AI_REAL_TEXT_PRECISION 8 when ai_real is float 16 when ai_real is double --- code/Collada/ColladaExporter.cpp | 2 +- code/Obj/ObjExporter.cpp | 4 ++-- code/Ply/PlyExporter.cpp | 2 +- code/STL/STLExporter.cpp | 2 +- code/Step/StepExporter.cpp | 16 ++++++++-------- code/X/XFileExporter.cpp | 4 ++-- include/assimp/defs.h | 6 ++++++ 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/code/Collada/ColladaExporter.cpp b/code/Collada/ColladaExporter.cpp index 7c21dde43..639f0e032 100644 --- a/code/Collada/ColladaExporter.cpp +++ b/code/Collada/ColladaExporter.cpp @@ -99,7 +99,7 @@ ColladaExporter::ColladaExporter( const aiScene* pScene, IOSystem* pIOSystem, co , mFile(file) { // make sure that all formatting happens using the standard, C locale and not the user's current locale mOutput.imbue( std::locale("C") ); - mOutput.precision(16); + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); mScene = pScene; mSceneOwned = false; diff --git a/code/Obj/ObjExporter.cpp b/code/Obj/ObjExporter.cpp index 08cba43f7..0a0dbd62c 100644 --- a/code/Obj/ObjExporter.cpp +++ b/code/Obj/ObjExporter.cpp @@ -126,9 +126,9 @@ ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMt // make sure that all formatting happens using the standard, C locale and not the user's current locale const std::locale& l = std::locale("C"); mOutput.imbue(l); - mOutput.precision(16); + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); mOutputMat.imbue(l); - mOutputMat.precision(16); + mOutputMat.precision(ASSIMP_AI_REAL_TEXT_PRECISION); WriteGeometryFile(noMtl); if ( !noMtl ) { diff --git a/code/Ply/PlyExporter.cpp b/code/Ply/PlyExporter.cpp index 4f9fa6c6f..5e21a88ac 100644 --- a/code/Ply/PlyExporter.cpp +++ b/code/Ply/PlyExporter.cpp @@ -111,7 +111,7 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina // make sure that all formatting happens using the standard, C locale and not the user's current locale const std::locale& l = std::locale("C"); mOutput.imbue(l); - mOutput.precision(16); + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); unsigned int faces = 0u, vertices = 0u, components = 0u; for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) { diff --git a/code/STL/STLExporter.cpp b/code/STL/STLExporter.cpp index d56c42835..43bc752ae 100644 --- a/code/STL/STLExporter.cpp +++ b/code/STL/STLExporter.cpp @@ -111,7 +111,7 @@ STLExporter::STLExporter(const char* _filename, const aiScene* pScene, bool expo // make sure that all formatting happens using the standard, C locale and not the user's current locale const std::locale& l = std::locale("C"); mOutput.imbue(l); - mOutput.precision(16); + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); if (binary) { char buf[80] = {0} ; buf[0] = 'A'; buf[1] = 's'; buf[2] = 's'; buf[3] = 'i'; buf[4] = 'm'; buf[5] = 'p'; diff --git a/code/Step/StepExporter.cpp b/code/Step/StepExporter.cpp index 2b4dbdbac..70035d9ea 100644 --- a/code/Step/StepExporter.cpp +++ b/code/Step/StepExporter.cpp @@ -143,15 +143,15 @@ namespace { // ------------------------------------------------------------------------------------------------ // Constructor for a specific scene to export StepExporter::StepExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, - const std::string& file, const ExportProperties* pProperties): - mProperties(pProperties),mIOSystem(pIOSystem),mFile(file), mPath(path), - mScene(pScene), endstr(";\n") { - CollectTrafos(pScene->mRootNode, trafos); - CollectMeshes(pScene->mRootNode, meshes); + const std::string& file, const ExportProperties* pProperties) : + mProperties(pProperties), mIOSystem(pIOSystem), mFile(file), mPath(path), + mScene(pScene), endstr(";\n") { + CollectTrafos(pScene->mRootNode, trafos); + CollectMeshes(pScene->mRootNode, meshes); // make sure that all formatting happens using the standard, C locale and not the user's current locale - mOutput.imbue( std::locale("C") ); - mOutput.precision(16); + mOutput.imbue(std::locale("C")); + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); // start writing WriteFile(); @@ -166,7 +166,7 @@ void StepExporter::WriteFile() mOutput.setf(std::ios::fixed); // precision for double // see http://stackoverflow.com/questions/554063/how-do-i-print-a-double-value-with-full-precision-using-cout - mOutput.precision(16); + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); // standard color aiColor4D fColor; diff --git a/code/X/XFileExporter.cpp b/code/X/XFileExporter.cpp index b2cc51852..ae9fd58fc 100644 --- a/code/X/XFileExporter.cpp +++ b/code/X/XFileExporter.cpp @@ -113,7 +113,7 @@ XFileExporter::XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const s { // make sure that all formatting happens using the standard, C locale and not the user's current locale mOutput.imbue( std::locale("C") ); - mOutput.precision(16); + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); // start writing WriteFile(); @@ -134,7 +134,7 @@ void XFileExporter::WriteFile() { // note, that all realnumber values must be comma separated in x files mOutput.setf(std::ios::fixed); - mOutput.precision(16); // precision for double + mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); // precision for ai_real // entry of writing the file WriteHeader(); diff --git a/include/assimp/defs.h b/include/assimp/defs.h index 2631263f5..1b9a97b6b 100644 --- a/include/assimp/defs.h +++ b/include/assimp/defs.h @@ -243,10 +243,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. typedef double ai_real; typedef signed long long int ai_int; typedef unsigned long long int ai_uint; +#ifndef ASSIMP_AI_REAL_TEXT_PRECISION +#define ASSIMP_AI_REAL_TEXT_PRECISION 16 +#endif // ASSIMP_AI_REAL_TEXT_PRECISION #else // ASSIMP_DOUBLE_PRECISION typedef float ai_real; typedef signed int ai_int; typedef unsigned int ai_uint; +#ifndef ASSIMP_AI_REAL_TEXT_PRECISION +#define ASSIMP_AI_REAL_TEXT_PRECISION 8 +#endif // ASSIMP_AI_REAL_TEXT_PRECISION #endif // ASSIMP_DOUBLE_PRECISION ////////////////////////////////////////////////////////////////////////// From 8f43fb144ac07a4dec9ae1e376bed37426951cee Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Mon, 24 Jun 2019 14:55:48 +0100 Subject: [PATCH 03/10] Add "importerIndex" Importer property This indicates the index of the Importer that was selected, or -1 if did not find one at all. --- code/Common/Importer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index 8931bfa03..91b50859a 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -590,10 +590,12 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) // Find an worker class which can handle the file BaseImporter* imp = NULL; + SetPropertyInteger("importerIndex", -1); for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) { if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, false)) { imp = pimpl->mImporter[a]; + SetPropertyInteger("importerIndex", a); break; } } @@ -606,6 +608,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) { if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, true)) { imp = pimpl->mImporter[a]; + SetPropertyInteger("importerIndex", a); break; } } From 6d07473550bfe4a7cee84e1cb59273329a8422d7 Mon Sep 17 00:00:00 2001 From: Mike Samsonov Date: Thu, 27 Jun 2019 17:59:55 +0100 Subject: [PATCH 04/10] all textures use relative path except embedded, this is fix for it --- code/FBX/FBXConverter.cpp | 4 ++-- test/unit/utFBXImporterExporter.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code/FBX/FBXConverter.cpp b/code/FBX/FBXConverter.cpp index 5031665a6..ccbfc9b40 100644 --- a/code/FBX/FBXConverter.cpp +++ b/code/FBX/FBXConverter.cpp @@ -1642,7 +1642,7 @@ namespace Assimp { out_tex->pcData = reinterpret_cast(const_cast(video).RelinquishContent()); // try to extract a hint from the file extension - const std::string& filename = video.FileName().empty() ? video.RelativeFilename() : video.FileName(); + const std::string& filename = video.RelativeFilename().empty() ? video.FileName() : video.RelativeFilename(); std::string ext = BaseImporter::GetExtension(filename); if (ext == "jpeg") { @@ -1653,7 +1653,7 @@ namespace Assimp { memcpy(out_tex->achFormatHint, ext.c_str(), ext.size()); } - out_tex->mFilename.Set(video.FileName().c_str()); + out_tex->mFilename.Set(filename.c_str()); return static_cast(textures.size() - 1); } diff --git a/test/unit/utFBXImporterExporter.cpp b/test/unit/utFBXImporterExporter.cpp index 77d7e9523..3180d96a2 100644 --- a/test/unit/utFBXImporterExporter.cpp +++ b/test/unit/utFBXImporterExporter.cpp @@ -241,6 +241,7 @@ TEST_F(utFBXImporterExporter, importEmbeddedAsciiTest) { aiString path; aiTextureMapMode modes[2]; EXPECT_EQ(aiReturn_SUCCESS, mat->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, nullptr, nullptr, modes)); + ASSERT_STREQ(path.C_Str(), "..\\..\\..\\Desktop\\uv_test.png"); ASSERT_EQ(1, scene->mNumTextures); ASSERT_TRUE(scene->mTextures[0]->pcData); From f5ece83f315e9f229c0892ad0ce4348ac15508fa Mon Sep 17 00:00:00 2001 From: Rob Conde Date: Fri, 28 Jun 2019 16:12:58 -0400 Subject: [PATCH 05/10] initial unnamed node uniqueness index outside of loop --- code/LWO/LWOLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/LWO/LWOLoader.cpp b/code/LWO/LWOLoader.cpp index d3c3b5ca0..1e5b92c32 100644 --- a/code/LWO/LWOLoader.cpp +++ b/code/LWO/LWOLoader.cpp @@ -1328,6 +1328,7 @@ void LWOImporter::LoadLWO2File() bool skip = false; LE_NCONST uint8_t* const end = mFileBuffer + fileSize; + unsigned int iUnnamed = 0; while (true) { if (mFileBuffer + sizeof(IFF::ChunkHeader) > end)break; @@ -1339,7 +1340,6 @@ void LWOImporter::LoadLWO2File() break; } uint8_t* const next = mFileBuffer+head.length; - unsigned int iUnnamed = 0; if(!head.length) { mFileBuffer = next; From ab55fb27c3c9cc954df05c06c734402ac4661284 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 2 Jul 2019 13:38:04 +0200 Subject: [PATCH 06/10] Fix a GCC 9 warning: assimp/include/assimp/material.inl: In member function 'aiReturn aiMaterial::Get(const char*, unsigned int, unsigned int, aiColor3D&) const': assimp/include/assimp/material.inl:176:33: error: implicitly-declared 'aiColor3D& aiColor3D::operator=(const aiColor3D&)' is deprecated [-Werror=deprecated-copy] 176 | pOut = aiColor3D(c.r,c.g,c.b); --- include/assimp/types.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/assimp/types.h b/include/assimp/types.h index 748e4851f..331b8cd03 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -161,7 +161,14 @@ struct aiColor3D explicit aiColor3D (ai_real _r) : r(_r), g(_r), b(_r) {} aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {} - /** Component-wise comparison */ + aiColor3D &operator=(const aiColor3D &o) { + r = o.r; + g = o.g; + b = o.b; + return *this; + } + + /** Component-wise comparison */ // TODO: add epsilon? bool operator == (const aiColor3D& other) const {return r == other.r && g == other.g && b == other.b;} From 96f16c7aea65eda75ddb381135cb92ed0578fc74 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 2 Jul 2019 19:48:53 +0200 Subject: [PATCH 07/10] closes https://github.com/assimp/assimp/issues/2527: use correct macro for Assimp-exporter. --- code/CMakeLists.txt | 2 +- include/assimp/config.h.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 40840759b..9c484910c 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -331,7 +331,7 @@ ADD_ASSIMP_EXPORTER( ASSBIN Assbin/AssbinExporter.cpp ) -ADD_ASSIMP_IMPORTER( ASSXML +ADD_ASSIMP_EXPORTER( ASSXML Assxml/AssxmlExporter.h Assxml/AssxmlExporter.cpp ) diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index c42aa63da..c95f0e160 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -142,7 +142,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @brief Specifies the maximum angle that may be between two vertex tangents * that their tangents and bi-tangents are smoothed. * - * This applies to the CalcTangentSpace-Step. The angle is specified + * This applies to the CalcTangentSpace-Step. TFvhe angle is specified * in degrees. The maximum value is 175. * Property type: float. Default value: 45 degrees */ From 1fc232effae7385c310fa228ad2014eea51c49eb Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 2 Jul 2019 21:46:52 +0200 Subject: [PATCH 08/10] closes https://github.com/assimp/assimp/issues/2368: just fix it --- code/FBX/FBXConverter.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/code/FBX/FBXConverter.cpp b/code/FBX/FBXConverter.cpp index ccbfc9b40..9906fcdf8 100644 --- a/code/FBX/FBXConverter.cpp +++ b/code/FBX/FBXConverter.cpp @@ -1255,7 +1255,7 @@ namespace Assimp { // mapping from output indices to DOM indexing, needed to resolve weights std::vector reverseMapping; - + std::map translateIndexMap; if (process_weights) { reverseMapping.resize(count_vertices); } @@ -1363,6 +1363,7 @@ namespace Assimp { if (reverseMapping.size()) { reverseMapping[cursor] = in_cursor; + translateIndexMap[in_cursor] = cursor; } out_mesh->mVertices[cursor] = vertices[in_cursor]; @@ -1394,6 +1395,42 @@ namespace Assimp { ConvertWeights(out_mesh, model, mesh, node_global_transform, index, &reverseMapping); } + std::vector animMeshes; + for (const BlendShape* blendShape : mesh.GetBlendShapes()) { + for (const BlendShapeChannel* blendShapeChannel : blendShape->BlendShapeChannels()) { + const std::vector& shapeGeometries = blendShapeChannel->GetShapeGeometries(); + for (size_t i = 0; i < shapeGeometries.size(); i++) { + aiAnimMesh* animMesh = aiCreateAnimMesh(out_mesh); + const ShapeGeometry* shapeGeometry = shapeGeometries.at(i); + const std::vector& vertices = shapeGeometry->GetVertices(); + const std::vector& normals = shapeGeometry->GetNormals(); + const std::vector& indices = shapeGeometry->GetIndices(); + animMesh->mName.Set(FixAnimMeshName(shapeGeometry->Name())); + for (size_t j = 0; j < indices.size(); j++) { + const unsigned int o_index = indices.at(j); + //unsigned int index = translateIndexMap[indices.at(j)]; + unsigned int index = indices.at(j); + aiVector3D vertex = vertices.at(j); + aiVector3D normal = normals.at(j); + unsigned int count = 0; + const unsigned int* outIndices = mesh.ToOutputVertexIndex(index, count); + for (unsigned int k = 0; k < count; k++) { + //unsigned int index = outIndices[k]; + unsigned int index = translateIndexMap[outIndices[k]]; + + animMesh->mVertices[index] += vertex; + if (animMesh->mNormals != nullptr) { + animMesh->mNormals[index] += normal; + animMesh->mNormals[index].NormalizeSafe(); + } + } + } + animMesh->mWeight = shapeGeometries.size() > 1 ? blendShapeChannel->DeformPercent() / 100.0f : 1.0f; + animMeshes.push_back(animMesh); + } + } + } + return static_cast(meshes.size() - 1); } From 0ec5eb752cce64f98929c9d4892b144910cac0f5 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 3 Jul 2019 12:50:01 +0200 Subject: [PATCH 09/10] Update FBXConverter.cpp Removing dead and unused code. --- code/FBX/FBXConverter.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/FBX/FBXConverter.cpp b/code/FBX/FBXConverter.cpp index 9906fcdf8..2c72702c6 100644 --- a/code/FBX/FBXConverter.cpp +++ b/code/FBX/FBXConverter.cpp @@ -1407,15 +1407,12 @@ namespace Assimp { const std::vector& indices = shapeGeometry->GetIndices(); animMesh->mName.Set(FixAnimMeshName(shapeGeometry->Name())); for (size_t j = 0; j < indices.size(); j++) { - const unsigned int o_index = indices.at(j); - //unsigned int index = translateIndexMap[indices.at(j)]; unsigned int index = indices.at(j); aiVector3D vertex = vertices.at(j); aiVector3D normal = normals.at(j); unsigned int count = 0; const unsigned int* outIndices = mesh.ToOutputVertexIndex(index, count); for (unsigned int k = 0; k < count; k++) { - //unsigned int index = outIndices[k]; unsigned int index = translateIndexMap[outIndices[k]]; animMesh->mVertices[index] += vertex; From 01070b4de7ef2788e75e7cab163e3a134148a240 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 4 Jul 2019 22:34:11 +0200 Subject: [PATCH 10/10] closes https://github.com/assimp/assimp/issues/2439: add null ptr test before calling hasAttr. --- port/PyAssimp/pyassimp/helper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/port/PyAssimp/pyassimp/helper.py b/port/PyAssimp/pyassimp/helper.py index 62384f54f..4003fb5ad 100644 --- a/port/PyAssimp/pyassimp/helper.py +++ b/port/PyAssimp/pyassimp/helper.py @@ -274,6 +274,8 @@ def hasattr_silent(object, name): """ try: + if not object: + return False return hasattr(object, name) except AttributeError: return False