From 1c9406b2f59d5235f2b69192551f4cae391f4c92 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 12 May 2018 08:09:07 +0200 Subject: [PATCH 1/5] add linetest files to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2a3b68a50..f8dda3e8b 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ tools/assimp_cmd/Makefile # Tests test/results +test/readlinetest* # Python __pycache__ From ef605fecaa4c51f3b59f5d1038a9f7ddd2417967 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 12 May 2018 08:09:27 +0200 Subject: [PATCH 2/5] FBX: small optimization to avoind static computation in loop. --- code/FBXBinaryTokenizer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/FBXBinaryTokenizer.cpp b/code/FBXBinaryTokenizer.cpp index d6c34de6f..b81a9f945 100644 --- a/code/FBXBinaryTokenizer.cpp +++ b/code/FBXBinaryTokenizer.cpp @@ -448,8 +448,8 @@ void TokenizeBinary(TokenList& output_tokens, const char* input, unsigned int le /*Result ignored*/ ReadByte(input, cursor, input + length); const uint32_t version = ReadWord(input, cursor, input + length); const bool is64bits = version >= 7500; - while (cursor < input + length) - { + const char *end = input + length; + while (cursor < end ) { if (!ReadScope(output_tokens, input, cursor, input + length, is64bits)) { break; } From f93ee9daced8e77227bdeba50fffd5e596eabe99 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 12 May 2018 08:10:26 +0200 Subject: [PATCH 3/5] closes https://github.com/assimp/assimp/issues/1780: check against nullptr before accessing normal data in aiMesh instance. --- code/glTF2Exporter.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 5376788b2..9bb99b0b0 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -728,8 +728,10 @@ void glTF2Exporter::ExportMeshes() /******************** Normals ********************/ // Normalize all normals as the validator can emit a warning otherwise - for (auto i = 0u; i < aim->mNumVertices; ++i) { - aim->mNormals[i].Normalize(); + if ( nullptr != aim->mNormals) { + for ( auto i = 0u; i < aim->mNumVertices; ++i ) { + aim->mNormals[ i ].Normalize(); + } } Ref n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); From 950496c351ff7a438c812b6b4719343d8ea4ccd9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 12 May 2018 08:39:22 +0200 Subject: [PATCH 4/5] some minor refactorings. --- code/glTF2Exporter.cpp | 17 ++++++++++------- code/glTF2Exporter.h | 28 ++++++++++++---------------- test/unit/utglTF2ImportExport.cpp | 1 + 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 9bb99b0b0..d4b3d67de 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -138,28 +138,29 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai } } +glTF2Exporter::~glTF2Exporter() { + // empty +} + /* * Copy a 4x4 matrix from struct aiMatrix to typedef mat4. * Also converts from row-major to column-major storage. */ -static void CopyValue(const aiMatrix4x4& v, mat4& o) -{ +static void CopyValue(const aiMatrix4x4& v, mat4& o) { o[ 0] = v.a1; o[ 1] = v.b1; o[ 2] = v.c1; o[ 3] = v.d1; o[ 4] = v.a2; o[ 5] = v.b2; o[ 6] = v.c2; o[ 7] = v.d2; o[ 8] = v.a3; o[ 9] = v.b3; o[10] = v.c3; o[11] = v.d3; o[12] = v.a4; o[13] = v.b4; o[14] = v.c4; o[15] = v.d4; } -static void CopyValue(const aiMatrix4x4& v, aiMatrix4x4& o) -{ +static void CopyValue(const aiMatrix4x4& v, aiMatrix4x4& o) { o.a1 = v.a1; o.a2 = v.a2; o.a3 = v.a3; o.a4 = v.a4; o.b1 = v.b1; o.b2 = v.b2; o.b3 = v.b3; o.b4 = v.b4; o.c1 = v.c1; o.c2 = v.c2; o.c3 = v.c3; o.c4 = v.c4; o.d1 = v.d1; o.d2 = v.d2; o.d3 = v.d3; o.d4 = v.d4; } -static void IdentityMatrix4(mat4& o) -{ +static void IdentityMatrix4(mat4& o) { o[ 0] = 1; o[ 1] = 0; o[ 2] = 0; o[ 3] = 0; o[ 4] = 0; o[ 5] = 1; o[ 6] = 0; o[ 7] = 0; o[ 8] = 0; o[ 9] = 0; o[10] = 1; o[11] = 0; @@ -169,7 +170,9 @@ static void IdentityMatrix4(mat4& o) inline Ref ExportData(Asset& a, std::string& meshName, Ref& buffer, unsigned int count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, bool isIndices = false) { - if (!count || !data) return Ref(); + if (!count || !data) { + return Ref(); + } unsigned int numCompsIn = AttribType::GetNumComponents(typeIn); unsigned int numCompsOut = AttribType::GetNumComponents(typeOut); diff --git a/code/glTF2Exporter.h b/code/glTF2Exporter.h index ff94be9e9..616a1177c 100644 --- a/code/glTF2Exporter.h +++ b/code/glTF2Exporter.h @@ -87,28 +87,15 @@ namespace Assimp // ------------------------------------------------------------------------------------------------ /** Helper class to export a given scene to an glTF file. */ // ------------------------------------------------------------------------------------------------ - class glTF2Exporter - { + class glTF2Exporter { public: /// Constructor for a specific scene to export glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties, bool binary); + ~glTF2Exporter(); - private: - - const char* mFilename; - IOSystem* mIOSystem; - const aiScene* mScene; - const ExportProperties* mProperties; - - std::map mTexturesByPath; - - std::shared_ptr mAsset; - - std::vector mBodyData; - + protected: void WriteBinaryData(IOStream* outfile, std::size_t sceneLength); - void GetTexSampler(const aiMaterial* mat, glTF2::Ref texture, aiTextureType tt, unsigned int slot); void GetMatTexProp(const aiMaterial* mat, unsigned int& prop, const char* propName, aiTextureType tt, unsigned int idx); void GetMatTexProp(const aiMaterial* mat, float& prop, const char* propName, aiTextureType tt, unsigned int idx); @@ -126,6 +113,15 @@ namespace Assimp unsigned int ExportNode(const aiNode* node, glTF2::Ref& parent); void ExportScene(); void ExportAnimations(); + + private: + const char* mFilename; + IOSystem* mIOSystem; + const aiScene* mScene; + const ExportProperties* mProperties + std::map mTexturesByPath; + std::shared_ptr mAsset; + std::vector mBodyData; }; } diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 91b8917a8..58ebe3017 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -89,4 +89,5 @@ TEST_F( utglTF2ImportExport, importBinaryglTF2FromFileTest ) { TEST_F( utglTF2ImportExport, exportglTF2FromFileTest ) { EXPECT_TRUE( exporterTest() ); } + #endif // ASSIMP_BUILD_NO_EXPORT From e3548fe85046eda679a064bee81db815a8e45e16 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 12 May 2018 08:50:17 +0200 Subject: [PATCH 5/5] Update glTF2Exporter.h Fix typo. --- code/glTF2Exporter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/glTF2Exporter.h b/code/glTF2Exporter.h index 616a1177c..06bc5ad40 100644 --- a/code/glTF2Exporter.h +++ b/code/glTF2Exporter.h @@ -118,7 +118,7 @@ namespace Assimp const char* mFilename; IOSystem* mIOSystem; const aiScene* mScene; - const ExportProperties* mProperties + const ExportProperties* mProperties; std::map mTexturesByPath; std::shared_ptr mAsset; std::vector mBodyData;