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/code/Collada/ColladaExporter.cpp b/code/Collada/ColladaExporter.cpp index 356eaad40..cace8460e 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/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(); 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; } } diff --git a/code/FBX/FBXConverter.cpp b/code/FBX/FBXConverter.cpp index 5031665a6..2c72702c6 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,39 @@ 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++) { + 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 = 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); } @@ -1642,7 +1676,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 +1687,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/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; 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/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 */ diff --git a/include/assimp/defs.h b/include/assimp/defs.h index 519a7653a..05a5e3fd4 100644 --- a/include/assimp/defs.h +++ b/include/assimp/defs.h @@ -241,10 +241,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 ////////////////////////////////////////////////////////////////////////// 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;} 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 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);