From e741e7aec6fe479d6eb638c08564bcee707e3633 Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Sat, 2 Dec 2017 23:16:10 +0100 Subject: [PATCH 01/39] Update MD5Loader.h --- code/MD5Loader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/MD5Loader.h b/code/MD5Loader.h index 9dfc08226..a68655f55 100644 --- a/code/MD5Loader.h +++ b/code/MD5Loader.h @@ -144,7 +144,7 @@ protected: // ------------------------------------------------------------------- /** Load the contents of a specific file into memory and - * alocates a buffer to keep it. + * allocates a buffer to keep it. * * mBuffer is modified to point to this buffer. * @param pFile File stream to be read From 3e0b072263fd27b4fb709aea77ef2bf5182c0b67 Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Sat, 9 Dec 2017 23:42:23 +0100 Subject: [PATCH 02/39] Update FBXBinaryTokenizer.cpp --- code/FBXBinaryTokenizer.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/code/FBXBinaryTokenizer.cpp b/code/FBXBinaryTokenizer.cpp index 550859345..be73eaa95 100644 --- a/code/FBXBinaryTokenizer.cpp +++ b/code/FBXBinaryTokenizer.cpp @@ -435,11 +435,6 @@ void TokenizeBinary(TokenList& output_tokens, const char* input, unsigned int le TokenizeError("file is too short",0); } - if (strncmp(input,"Kaydara FBX Binary",18)) { - TokenizeError("magic bytes not found",0); - } - - //uint32_t offset = 0x15; const char* cursor = input + 0x15; From 0c2f4abe78be157645be34f617a1bd3b942390c0 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 10 Dec 2017 18:25:50 +0100 Subject: [PATCH 03/39] Update CREDITS Add list of patreons. --- CREDITS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CREDITS b/CREDITS index 43134ac03..df41c482d 100644 --- a/CREDITS +++ b/CREDITS @@ -158,3 +158,11 @@ Contributed X File exporter Contributed Step (stp) exporter For a more detailed list just check: https://github.com/assimp/assimp/network/members + +Patreons: +- migenius +- Marcus +- Cort +- elect +- Steffen + From 28b01cbdd14c468c246ebea6b0275f870f402b62 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 11 Dec 2017 13:20:19 +0100 Subject: [PATCH 04/39] Update to 4.1.0 --- code/Version.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Version.cpp b/code/Version.cpp index 2cd759817..fe9a2fdaa 100644 --- a/code/Version.cpp +++ b/code/Version.cpp @@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ScenePrivate.h" static const unsigned int MajorVersion = 4; -static const unsigned int MinorVersion = 0; +static const unsigned int MinorVersion = 1; // -------------------------------------------------------------------------------- // Legal information string - dont't remove this. From 406a06705e005742b4ed36f92e3f09d9a222cfc8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 11 Dec 2017 13:21:35 +0100 Subject: [PATCH 05/39] Update Doxyfile.in Update version --- doc/Doxyfile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 8d51259a8..ffe39f9f7 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -32,7 +32,7 @@ PROJECT_NAME = Assimp # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = "v3.1.1 (June 2014)" +PROJECT_NUMBER = "v4.1. (December 2018)" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer From 65d29c542091c21e72b143818b708333747e36ad Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 11 Dec 2017 13:22:20 +0100 Subject: [PATCH 06/39] Update CMakeLists.txt Update version --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fc9af467..dd2317cca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,8 +129,8 @@ ENDIF(NOT BUILD_SHARED_LIBS) # Define here the needed parameters SET (ASSIMP_VERSION_MAJOR 4) -SET (ASSIMP_VERSION_MINOR 0) -SET (ASSIMP_VERSION_PATCH 1) +SET (ASSIMP_VERSION_MINOR 1) +SET (ASSIMP_VERSION_PATCH 0) SET (ASSIMP_VERSION ${ASSIMP_VERSION_MAJOR}.${ASSIMP_VERSION_MINOR}.${ASSIMP_VERSION_PATCH}) SET (ASSIMP_SOVERSION 4) SET (PROJECT_VERSION "${ASSIMP_VERSION}") From e8139ef5159737b62f759edf6ccd6fcbd810ea32 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 11 Dec 2017 13:30:16 +0100 Subject: [PATCH 07/39] Update utVersion.cpp Fix unittests. --- test/unit/utVersion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/utVersion.cpp b/test/unit/utVersion.cpp index 677a131c9..a424a27cf 100644 --- a/test/unit/utVersion.cpp +++ b/test/unit/utVersion.cpp @@ -54,7 +54,7 @@ TEST_F( utVersion, aiGetLegalStringTest ) { } TEST_F( utVersion, aiGetVersionMinorTest ) { - EXPECT_EQ( aiGetVersionMinor(), 0U ); + EXPECT_EQ( aiGetVersionMinor(), 1U ); } TEST_F( utVersion, aiGetVersionMajorTest ) { From 7337474b6ccf850919377e4e4072d34397f81175 Mon Sep 17 00:00:00 2001 From: Teybeo Date: Mon, 11 Dec 2017 16:26:00 +0100 Subject: [PATCH 08/39] Fix 3MF define typo --- code/Exporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Exporter.cpp b/code/Exporter.cpp index 3fc31a722..0281e4e99 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -165,7 +165,7 @@ Exporter::ExportFormatEntry gExporters[] = Exporter::ExportFormatEntry( "x3d", "Extensible 3D", "x3d" , &ExportSceneX3D, 0 ), #endif -#ifndef ASSIMP_BUILD_NO3MF_EXPORTER +#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER Exporter::ExportFormatEntry( "3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0 ) #endif }; From 8cd1ede9baf2476a5cae280b211afa31c3b3c60d Mon Sep 17 00:00:00 2001 From: Teybeo Date: Mon, 11 Dec 2017 16:26:45 +0100 Subject: [PATCH 09/39] Fix 3MF define typo --- code/D3MFExporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/D3MFExporter.cpp b/code/D3MFExporter.cpp index 162d20764..229e3f261 100644 --- a/code/D3MFExporter.cpp +++ b/code/D3MFExporter.cpp @@ -324,5 +324,5 @@ void D3MFExporter::writeRelInfoToFile( const std::string &folder, const std::str } // Namespace D3MF } // Namespace Assimp -#endif // ASSIMP_BUILD_NO3MF_EXPORTER +#endif // ASSIMP_BUILD_NO_3MF_EXPORTER #endif // ASSIMP_BUILD_NO_EXPORT From 99031997bdb87074138505da977122bc361dd57b Mon Sep 17 00:00:00 2001 From: Teybeo Date: Mon, 11 Dec 2017 16:27:27 +0100 Subject: [PATCH 10/39] Fix 3MF define typo --- code/D3MFExporter.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/D3MFExporter.h b/code/D3MFExporter.h index 16efabf29..b6be73976 100644 --- a/code/D3MFExporter.h +++ b/code/D3MFExporter.h @@ -59,7 +59,7 @@ class IOStream; namespace D3MF { #ifndef ASSIMP_BUILD_NO_EXPORT -#ifndef ASSIMP_BUILD_NO3MF_EXPORTER +#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER struct OpcPackageRelationship; @@ -95,7 +95,7 @@ private: std::vector mRelations; }; -#endif // ASSIMP_BUILD_NO3MF_EXPORTER +#endif // ASSIMP_BUILD_NO_3MF_EXPORTER #endif // ASSIMP_BUILD_NO_EXPORT } // Namespace D3MF From f9b599355c3b537bcb48f734d0a98ed1c22566d2 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Tue, 12 Dec 2017 02:28:03 -0800 Subject: [PATCH 11/39] unzip: fix build with older zlib Fixes "unzip.c:150:11: error: unknown type name 'z_crc_t'" --- contrib/unzip/unzip.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/unzip/unzip.c b/contrib/unzip/unzip.c index e8b62e763..fea6e8913 100644 --- a/contrib/unzip/unzip.c +++ b/contrib/unzip/unzip.c @@ -41,6 +41,10 @@ woven in by Terry Thorsen 1/2003. #include "zlib.h" #include "unzip.h" +#if ZLIB_VERNUM < 0x1270 +typedef unsigned long z_crc_t; +#endif + #ifdef STDC # include # include From 30ae14fae9ca2d2a2aaa185395c75e615518af87 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 12 Dec 2017 18:40:28 +0200 Subject: [PATCH 12/39] B3DImporter: Add unique_to_array helper function --- code/B3DImporter.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index bc888fb66..46008bf31 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -267,6 +267,21 @@ T *B3DImporter::to_array( const vector &v ){ return p; } + +// ------------------------------------------------------------------------------------------------ +template +T **unique_to_array( vector > &v ){ + if( v.empty() ) { + return 0; + } + T **p = new T*[ v.size() ]; + for( size_t i = 0; i < v.size(); ++i ){ + p[i] = v[i].release(); + } + return p; +} + + // ------------------------------------------------------------------------------------------------ void B3DImporter::ReadTEXS(){ while( ChunkSize() ){ From acab4c327e53d9cdd468536861a5f5575ff7ae51 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 12 Dec 2017 18:42:14 +0200 Subject: [PATCH 13/39] B3DImporter: Store animations in unique_ptr --- code/B3DImporter.cpp | 10 ++++------ code/B3DImporter.h | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index 46008bf31..b3a01c79c 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -93,7 +93,6 @@ void DeleteAllBarePointers(std::vector& x) B3DImporter::~B3DImporter() { - DeleteAllBarePointers(_animations); } // ------------------------------------------------------------------------------------------------ @@ -515,11 +514,11 @@ void B3DImporter::ReadANIM(){ int frames=ReadInt(); float fps=ReadFloat(); - aiAnimation *anim=new aiAnimation; - _animations.push_back( anim ); + std::unique_ptr anim(new aiAnimation); anim->mDuration=frames; anim->mTicksPerSecond=fps; + _animations.emplace_back( std::move(anim) ); } // ------------------------------------------------------------------------------------------------ @@ -601,7 +600,6 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ _nodeAnims.clear(); - DeleteAllBarePointers(_animations); _animations.clear(); string t=ReadChunk(); @@ -715,12 +713,12 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ //animations if( _animations.size()==1 && _nodeAnims.size() ){ - aiAnimation *anim=_animations.back(); + aiAnimation *anim = _animations.back().get(); anim->mNumChannels=static_cast(_nodeAnims.size()); anim->mChannels=to_array( _nodeAnims ); scene->mNumAnimations=static_cast(_animations.size()); - scene->mAnimations=to_array( _animations ); + scene->mAnimations=unique_to_array( _animations ); } // convert to RH diff --git a/code/B3DImporter.h b/code/B3DImporter.h index 94644edd4..b283cfab6 100644 --- a/code/B3DImporter.h +++ b/code/B3DImporter.h @@ -49,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "BaseImporter.h" +#include #include struct aiNodeAnim; @@ -124,7 +125,7 @@ private: std::vector _nodes; std::vector _meshes; std::vector _nodeAnims; - std::vector _animations; + std::vector > _animations; }; } From f1707e920d9b0534757326dd5786e44774eae6a3 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 12 Dec 2017 18:54:41 +0200 Subject: [PATCH 14/39] B3DImporter: Store meshes in unique_ptr --- code/B3DImporter.cpp | 9 +++++---- code/B3DImporter.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index b3a01c79c..d764bd530 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -400,8 +400,7 @@ void B3DImporter::ReadTRIS( int v0 ){ Fail( "Bad material id" ); } - aiMesh *mesh=new aiMesh; - _meshes.push_back( mesh ); + std::unique_ptr mesh(new aiMesh); mesh->mMaterialIndex=matid; mesh->mNumFaces=0; @@ -429,6 +428,8 @@ void B3DImporter::ReadTRIS( int v0 ){ ++mesh->mNumFaces; ++face; } + + _meshes.emplace_back( std::move(mesh) ); } // ------------------------------------------------------------------------------------------------ @@ -635,7 +636,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ aiNode *node=_nodes[i]; for( size_t j=0;jmNumMeshes;++j ){ - aiMesh *mesh=_meshes[node->mMeshes[j]]; + aiMesh *mesh = _meshes[node->mMeshes[j]].get(); int n_tris=mesh->mNumFaces; int n_verts=mesh->mNumVertices=n_tris * 3; @@ -708,7 +709,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ //meshes scene->mNumMeshes= static_cast(_meshes.size()); - scene->mMeshes=to_array( _meshes ); + scene->mMeshes = unique_to_array( _meshes ); //animations if( _animations.size()==1 && _nodeAnims.size() ){ diff --git a/code/B3DImporter.h b/code/B3DImporter.h index b283cfab6..ef36c4618 100644 --- a/code/B3DImporter.h +++ b/code/B3DImporter.h @@ -123,7 +123,7 @@ private: std::vector _vertices; std::vector _nodes; - std::vector _meshes; + std::vector > _meshes; std::vector _nodeAnims; std::vector > _animations; }; From 08a35d4e1f44030276293d4a64863e802cee8464 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 12 Dec 2017 19:16:06 +0200 Subject: [PATCH 15/39] B3DImporter: Store materials in unique_ptr --- code/B3DImporter.cpp | 8 ++++---- code/B3DImporter.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index d764bd530..195ee04a8 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -309,8 +309,7 @@ void B3DImporter::ReadBRUS(){ /*int blend=**/ReadInt(); int fx=ReadInt(); - aiMaterial *mat=new aiMaterial; - _materials.push_back( mat ); + std::unique_ptr mat(new aiMaterial); // Name aiString ainame( name ); @@ -347,6 +346,7 @@ void B3DImporter::ReadBRUS(){ mat->AddProperty( &texname,AI_MATKEY_TEXTURE_DIFFUSE(0) ); } } + _materials.emplace_back( std::move(mat) ); } } @@ -702,10 +702,10 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ //material if( !_materials.size() ){ - _materials.push_back( new aiMaterial ); + _materials.emplace_back( std::unique_ptr(new aiMaterial) ); } scene->mNumMaterials= static_cast(_materials.size()); - scene->mMaterials=to_array( _materials ); + scene->mMaterials = unique_to_array( _materials ); //meshes scene->mNumMeshes= static_cast(_meshes.size()); diff --git a/code/B3DImporter.h b/code/B3DImporter.h index ef36c4618..f9645f594 100644 --- a/code/B3DImporter.h +++ b/code/B3DImporter.h @@ -117,7 +117,7 @@ private: std::vector _stack; std::vector _textures; - std::vector _materials; + std::vector > _materials; int _vflags,_tcsets,_tcsize; std::vector _vertices; From 824dfc314b80dc0e91505cb08a65a50e4e8d2ded Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 12 Dec 2017 19:39:41 +0200 Subject: [PATCH 16/39] B3DImporter: Store node animations in unique_ptr --- code/B3DImporter.cpp | 13 ++++++++----- code/B3DImporter.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index 195ee04a8..dd7b0d95e 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -546,7 +546,7 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){ node->mParent=parent; node->mTransformation=tform; - aiNodeAnim *nodeAnim=0; + std::unique_ptr nodeAnim; vector meshes; vector children; @@ -564,11 +564,10 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){ ReadANIM(); }else if( t=="KEYS" ){ if( !nodeAnim ){ - nodeAnim=new aiNodeAnim; - _nodeAnims.push_back( nodeAnim ); + nodeAnim.reset(new aiNodeAnim); nodeAnim->mNodeName=node->mName; } - ReadKEYS( nodeAnim ); + ReadKEYS( nodeAnim.get() ); }else if( t=="NODE" ){ aiNode *child=ReadNODE( node ); children.push_back( child ); @@ -576,6 +575,10 @@ aiNode *B3DImporter::ReadNODE( aiNode *parent ){ ExitChunk(); } + if (nodeAnim) { + _nodeAnims.emplace_back( std::move(nodeAnim) ); + } + node->mNumMeshes= static_cast(meshes.size()); node->mMeshes=to_array( meshes ); @@ -716,7 +719,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ aiAnimation *anim = _animations.back().get(); anim->mNumChannels=static_cast(_nodeAnims.size()); - anim->mChannels=to_array( _nodeAnims ); + anim->mChannels = unique_to_array( _nodeAnims ); scene->mNumAnimations=static_cast(_animations.size()); scene->mAnimations=unique_to_array( _animations ); diff --git a/code/B3DImporter.h b/code/B3DImporter.h index f9645f594..342b88a28 100644 --- a/code/B3DImporter.h +++ b/code/B3DImporter.h @@ -124,7 +124,7 @@ private: std::vector _nodes; std::vector > _meshes; - std::vector _nodeAnims; + std::vector > _nodeAnims; std::vector > _animations; }; From 89afe0780b99e7309cf6158ce3e23e1e76f242f3 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 12 Dec 2017 20:03:16 +0200 Subject: [PATCH 17/39] B3DImporter: Fix double free when reusing Importer --- code/B3DImporter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index dd7b0d95e..aa87609d4 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -702,6 +702,7 @@ void B3DImporter::ReadBB3D( aiScene *scene ){ //nodes scene->mRootNode=_nodes[0]; + _nodes.clear(); // node ownership now belongs to scene //material if( !_materials.size() ){ From 89ff8fc05d5a5f4517222b92a9642e4ab63b528b Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Tue, 12 Dec 2017 20:34:53 +0100 Subject: [PATCH 18/39] Add unit test for issue 1623 --- test/unit/utPLYImportExport.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unit/utPLYImportExport.cpp b/test/unit/utPLYImportExport.cpp index 82cc54bdb..dbb7f4292 100644 --- a/test/unit/utPLYImportExport.cpp +++ b/test/unit/utPLYImportExport.cpp @@ -85,6 +85,18 @@ TEST_F(utPLYImportExport, exportTest_Success ) { #endif // ASSIMP_BUILD_NO_EXPORT +//Test issue 1623, crash when loading two PLY files in a row +TEST_F(utPLYImportExport, importerMultipleTest) { + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); + + EXPECT_NE(nullptr, scene); + + scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0); + + EXPECT_NE(nullptr, scene); +} + TEST_F( utPLYImportExport, vertexColorTest ) { Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/float-color.ply", 0 ); From 50bcaf39fd60da3bc9cb5a2dffb7f2f26d1731e9 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Tue, 12 Dec 2017 20:48:51 +0100 Subject: [PATCH 19/39] Fix issue #1623 : crash when loading multiple PLY files Pointer mGeneratedMesh was not reset to nullptr when transfering ownership to pScene->mMeshes --- code/PlyLoader.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/code/PlyLoader.cpp b/code/PlyLoader.cpp index c6e862bf1..7c4614474 100644 --- a/code/PlyLoader.cpp +++ b/code/PlyLoader.cpp @@ -91,9 +91,9 @@ namespace // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer PLYImporter::PLYImporter() - : mBuffer() - , pcDOM() - , mGeneratedMesh(NULL){ + : mBuffer(nullptr) + , pcDOM(nullptr) + , mGeneratedMesh(nullptr){ // empty } @@ -196,7 +196,10 @@ void PLYImporter::InternReadFile(const std::string& pFile, if (!PLY::DOM::ParseInstance(streamedBuffer, &sPlyDom, this)) { if (mGeneratedMesh != NULL) + { delete(mGeneratedMesh); + mGeneratedMesh = nullptr; + } streamedBuffer.close(); throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#1)"); @@ -211,7 +214,10 @@ void PLYImporter::InternReadFile(const std::string& pFile, if (!PLY::DOM::ParseInstanceBinary(streamedBuffer, &sPlyDom, this, bIsBE)) { if (mGeneratedMesh != NULL) + { delete(mGeneratedMesh); + mGeneratedMesh = nullptr; + } streamedBuffer.close(); throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#2)"); @@ -220,7 +226,10 @@ void PLYImporter::InternReadFile(const std::string& pFile, else { if (mGeneratedMesh != NULL) + { delete(mGeneratedMesh); + mGeneratedMesh = nullptr; + } streamedBuffer.close(); throw DeadlyImportError("Invalid .ply file: Unknown file format"); @@ -230,7 +239,10 @@ void PLYImporter::InternReadFile(const std::string& pFile, { AI_DEBUG_INVALIDATE_PTR(this->mBuffer); if (mGeneratedMesh != NULL) + { delete(mGeneratedMesh); + mGeneratedMesh = nullptr; + } streamedBuffer.close(); throw DeadlyImportError("Invalid .ply file: Missing format specification"); @@ -252,7 +264,10 @@ void PLYImporter::InternReadFile(const std::string& pFile, if (mGeneratedMesh->mNumVertices < 3) { if (mGeneratedMesh != NULL) + { delete(mGeneratedMesh); + mGeneratedMesh = nullptr; + } streamedBuffer.close(); throw DeadlyImportError("Invalid .ply file: Not enough " @@ -289,6 +304,7 @@ void PLYImporter::InternReadFile(const std::string& pFile, pScene->mNumMeshes = 1; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes[0] = mGeneratedMesh; + mGeneratedMesh = nullptr; // generate a simple node structure pScene->mRootNode = new aiNode(); From 31a4ccaebb338deac016748e3cdfef1e2e5361fe Mon Sep 17 00:00:00 2001 From: Alexis Breust Date: Thu, 14 Dec 2017 16:11:12 +0100 Subject: [PATCH 20/39] Added support for generating glb2 (binary glTF 2) --- code/Exporter.cpp | 5 ++- code/glTF2AssetWriter.h | 1 + code/glTF2AssetWriter.inl | 92 +++++++++++++++++++++++++++++++++++++++ code/glTF2Exporter.cpp | 14 +++++- 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/code/Exporter.cpp b/code/Exporter.cpp index 0281e4e99..cb496490f 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -92,6 +92,7 @@ void ExportScene3DS(const char*, IOSystem*, const aiScene*, const ExportProperti void ExportSceneGLTF(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneGLB(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneGLTF2(const char*, IOSystem*, const aiScene*, const ExportProperties*); +void ExportSceneGLB2(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneAssxml(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperties*); @@ -151,6 +152,8 @@ Exporter::ExportFormatEntry gExporters[] = aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ), Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf2", &ExportSceneGLTF2, aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ), + Exporter::ExportFormatEntry( "glb2", "GL Transmission Format v. 2", "glb2", &ExportSceneGLB2, + aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ), #endif #ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER @@ -420,7 +423,7 @@ aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const c pimpl->mError = std::string("Found no exporter to handle this file format: ") + pFormatId; ASSIMP_END_EXCEPTION_REGION(aiReturn); - + return AI_FAILURE; } diff --git a/code/glTF2AssetWriter.h b/code/glTF2AssetWriter.h index bce2b1bd1..b4e7ffc2e 100644 --- a/code/glTF2AssetWriter.h +++ b/code/glTF2AssetWriter.h @@ -81,6 +81,7 @@ public: AssetWriter(Asset& asset); void WriteFile(const char* path); + void WriteGLBFile(const char* path); }; } diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index 8b2769a37..aaef7bccb 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -561,6 +561,98 @@ namespace glTF2 { } } + inline void AssetWriter::WriteGLBFile(const char* path) + { + std::unique_ptr outfile(mAsset.OpenFile(path, "wb", true)); + + if (outfile == 0) { + throw DeadlyExportError("Could not open output file: " + std::string(path)); + } + + // Padding with zeros make a invalid JSON for the gltf online validator + uint8_t padding[] = { '\n', '\n', '\n' }; + + // Adapt JSON so that it is not pointing to an external file, + // as this is required by the GLB spec'. + mDoc["buffers"][0].RemoveMember("uri"); + + // + // JSON chunk + // + + StringBuffer docBuffer; + Writer writer(docBuffer); + mDoc.Accept(writer); + + uint32_t jsonChunkLength = (docBuffer.GetSize() + 3) & ~3; // Round up to next multiple of 4 + auto paddingLength = jsonChunkLength - docBuffer.GetSize(); + std::cout << paddingLength << std::endl; + + GLB_Chunk jsonChunk; + jsonChunk.chunkLength = jsonChunkLength; + jsonChunk.chunkType = ChunkType_JSON; + AI_SWAP4(jsonChunk.chunkLength); + + outfile->Seek(sizeof(GLB_Header), aiOrigin_SET); + if (outfile->Write(&jsonChunk, 1, sizeof(GLB_Chunk)) != sizeof(GLB_Chunk)) { + throw DeadlyExportError("Failed to write scene data header!"); + } + if (outfile->Write(docBuffer.GetString(), 1, docBuffer.GetSize()) != docBuffer.GetSize()) { + throw DeadlyExportError("Failed to write scene data!"); + } + if (paddingLength && outfile->Write(padding, 1, paddingLength) != paddingLength) { + throw DeadlyExportError("Failed to write scene data padding!"); + } + + // + // Binary chunk + // + + uint32_t binaryChunkLength = 0; + if (mAsset.buffers.Size() > 0) { + Ref b = mAsset.buffers.Get(0u); + if (b->byteLength > 0) { + binaryChunkLength = (b->byteLength + 3) & ~3; // Round up to next multiple of 4 + auto paddingLength = binaryChunkLength - b->byteLength; + + GLB_Chunk binaryChunk; + binaryChunk.chunkLength = binaryChunkLength; + binaryChunk.chunkType = ChunkType_BIN; + AI_SWAP4(binaryChunk.chunkLength); + + size_t bodyOffset = sizeof(GLB_Header) + sizeof(GLB_Chunk) + jsonChunk.chunkLength; + outfile->Seek(bodyOffset, aiOrigin_SET); + if (outfile->Write(&binaryChunk, 1, sizeof(GLB_Chunk)) != sizeof(GLB_Chunk)) { + throw DeadlyExportError("Failed to write body data header!"); + } + if (outfile->Write(b->GetPointer(), 1, b->byteLength) != b->byteLength) { + throw DeadlyExportError("Failed to write body data!"); + } + if (paddingLength && outfile->Write(padding, 1, paddingLength) != paddingLength) { + throw DeadlyExportError("Failed to write body data padding!"); + } + } + } + + // + // Header + // + + GLB_Header header; + memcpy(header.magic, AI_GLB_MAGIC_NUMBER, sizeof(header.magic)); + + header.version = 2; + AI_SWAP4(header.version); + + header.length = uint32_t(sizeof(GLB_Header) + 2 * sizeof(GLB_Chunk) + jsonChunkLength + binaryChunkLength); + AI_SWAP4(header.length); + + outfile->Seek(0, aiOrigin_SET); + if (outfile->Write(&header, 1, sizeof(GLB_Header)) != sizeof(GLB_Header)) { + throw DeadlyExportError("Failed to write the header!"); + } + } + inline void AssetWriter::WriteMetadata() { Value asset; diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index c1a803c1f..82b95195f 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -77,6 +77,14 @@ namespace Assimp { glTF2Exporter exporter(pFile, pIOSystem, pScene, pProperties, false); } + // ------------------------------------------------------------------------------------------------ + // Worker function for exporting a scene to GLB. Prototyped and registered in Exporter.cpp + void ExportSceneGLB2(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties) + { + // invoke the exporter + glTF2Exporter exporter(pFile, pIOSystem, pScene, pProperties, true); + } + } // end of namespace Assimp glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene, @@ -118,7 +126,11 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai AssetWriter writer(*mAsset); - writer.WriteFile(filename); + if (isBinary) { + writer.WriteGLBFile(filename); + } else { + writer.WriteFile(filename); + } } /* From d09df8cc07ea81fce3e43332b72d6fabfaa95a72 Mon Sep 17 00:00:00 2001 From: Alexis Breust Date: Thu, 14 Dec 2017 16:18:17 +0100 Subject: [PATCH 21/39] Fixed leftover log --- code/Exporter.cpp | 2 +- code/glTF2AssetWriter.inl | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/code/Exporter.cpp b/code/Exporter.cpp index cb496490f..eebecd859 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -152,7 +152,7 @@ Exporter::ExportFormatEntry gExporters[] = aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ), Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf2", &ExportSceneGLTF2, aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ), - Exporter::ExportFormatEntry( "glb2", "GL Transmission Format v. 2", "glb2", &ExportSceneGLB2, + Exporter::ExportFormatEntry( "glb2", "GL Transmission Format v. 2 (binary)", "glb2", &ExportSceneGLB2, aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ), #endif diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index aaef7bccb..9734dc7c8 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -586,7 +586,6 @@ namespace glTF2 { uint32_t jsonChunkLength = (docBuffer.GetSize() + 3) & ~3; // Round up to next multiple of 4 auto paddingLength = jsonChunkLength - docBuffer.GetSize(); - std::cout << paddingLength << std::endl; GLB_Chunk jsonChunk; jsonChunk.chunkLength = jsonChunkLength; From 722420c5dc65d4f684e311b7ee969936d5b1543c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 16:51:47 +0100 Subject: [PATCH 22/39] diable unaigned pointer access temprary. --- code/MDLLoader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 2025d79b3..873da4c3e 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -416,7 +416,8 @@ void MDLImporter::InternReadFile_Quake1( ) { // get the first frame in the group BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames; - pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type); + //pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type); + ai_assert( false && "Unaligned pointer" ); } BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + pcHeader->num_verts)); From eb0608f2e9c1fa130ba41469783e8c150f40c9f9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:00:16 +0100 Subject: [PATCH 23/39] diable unaigned pointer access temprary, second one. --- code/MDLLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 873da4c3e..3a9f2c344 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -415,7 +415,7 @@ void MDLImporter::InternReadFile_Quake1( ) else { // get the first frame in the group - BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames; + //BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames; //pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type); ai_assert( false && "Unaligned pointer" ); } From 151d71bc697bb61bebc9cd90d890908cfe1ec275 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:21:17 +0100 Subject: [PATCH 24/39] fix misalignment in vector2 [] operator. --- include/assimp/vector2.inl | 10 +++++++++- include/assimp/vector3.inl | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 5ce13eece..ee6c4d2d4 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -114,7 +114,15 @@ const aiVector2t& aiVector2t::operator /= (TReal f) { // ------------------------------------------------------------------------------------------------ template TReal aiVector2t::operator[](unsigned int i) const { - return *(&x + i); + switch (i) { + case 0: + return x; + case 1: + return y; + default: + break; + } + return x; } // ------------------------------------------------------------------------------------------------ diff --git a/include/assimp/vector3.inl b/include/assimp/vector3.inl index a074bb23a..2b132c1a5 100644 --- a/include/assimp/vector3.inl +++ b/include/assimp/vector3.inl @@ -142,7 +142,6 @@ AI_FORCE_INLINE aiVector3t& aiVector3t::operator *= (const aiMatri // ------------------------------------------------------------------------------------------------ template AI_FORCE_INLINE TReal aiVector3t::operator[](unsigned int i) const { -// return *(&x + i); switch (i) { case 0: return x; From d29173aaa90a4dcb7735d259644e7b9be605d642 Mon Sep 17 00:00:00 2001 From: Alexis Breust Date: Thu, 14 Dec 2017 17:32:18 +0100 Subject: [PATCH 25/39] Following specification for padding --- code/glTF2AssetWriter.inl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index 9734dc7c8..6b1a50887 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -569,8 +569,8 @@ namespace glTF2 { throw DeadlyExportError("Could not open output file: " + std::string(path)); } - // Padding with zeros make a invalid JSON for the gltf online validator - uint8_t padding[] = { '\n', '\n', '\n' }; + // Padding with spaces as required by the spec + uint32_t padding = 0x20202020; // Adapt JSON so that it is not pointing to an external file, // as this is required by the GLB spec'. @@ -599,7 +599,7 @@ namespace glTF2 { if (outfile->Write(docBuffer.GetString(), 1, docBuffer.GetSize()) != docBuffer.GetSize()) { throw DeadlyExportError("Failed to write scene data!"); } - if (paddingLength && outfile->Write(padding, 1, paddingLength) != paddingLength) { + if (paddingLength && outfile->Write(&padding, 1, paddingLength) != paddingLength) { throw DeadlyExportError("Failed to write scene data padding!"); } @@ -627,7 +627,7 @@ namespace glTF2 { if (outfile->Write(b->GetPointer(), 1, b->byteLength) != b->byteLength) { throw DeadlyExportError("Failed to write body data!"); } - if (paddingLength && outfile->Write(padding, 1, paddingLength) != paddingLength) { + if (paddingLength && outfile->Write(&padding, 1, paddingLength) != paddingLength) { throw DeadlyExportError("Failed to write body data padding!"); } } From e0649b68220ff41c24be5a8faf3e03de3b4ebf5b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:42:59 +0100 Subject: [PATCH 26/39] fix misalignment in vector2 [] operator, the non-const one. --- include/assimp/vector2.inl | 58 ++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index ee6c4d2d4..97db2820c 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -60,24 +60,28 @@ aiVector2t::operator aiVector2t () const { } // ------------------------------------------------------------------------------------------------ template +inline void aiVector2t::Set( TReal pX, TReal pY) { x = pX; y = pY; } // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::SquareLength() const { return x*x + y*y; } // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::Length() const { return std::sqrt( SquareLength()); } // ------------------------------------------------------------------------------------------------ template +inline aiVector2t& aiVector2t::Normalize() { *this /= Length(); return *this; @@ -85,6 +89,7 @@ aiVector2t& aiVector2t::Normalize() { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator += (const aiVector2t& o) { x += o.x; y += o.y; return *this; @@ -92,6 +97,7 @@ const aiVector2t& aiVector2t::operator += (const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator -= (const aiVector2t& o) { x -= o.x; y -= o.y; return *this; @@ -99,6 +105,7 @@ const aiVector2t& aiVector2t::operator -= (const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator *= (TReal f) { x *= f; y *= f; return *this; @@ -106,6 +113,7 @@ const aiVector2t& aiVector2t::operator *= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator /= (TReal f) { x /= f; y /= f; return *this; @@ -113,6 +121,7 @@ const aiVector2t& aiVector2t::operator /= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::operator[](unsigned int i) const { switch (i) { case 0: @@ -127,24 +136,36 @@ TReal aiVector2t::operator[](unsigned int i) const { // ------------------------------------------------------------------------------------------------ template +inline TReal& aiVector2t::operator[](unsigned int i) { - return *(&x + i); + switch (i) { + case 0: + return x; + case 1: + return y; + default: + break; + } + return x; } // ------------------------------------------------------------------------------------------------ template +inline bool aiVector2t::operator== (const aiVector2t& other) const { return x == other.x && y == other.y; } // ------------------------------------------------------------------------------------------------ template +inline bool aiVector2t::operator!= (const aiVector2t& other) const { return x != other.x || y != other.y; } // --------------------------------------------------------------------------- template +inline bool aiVector2t::Equal(const aiVector2t& other, TReal epsilon) const { return std::abs(x - other.x) <= epsilon && @@ -153,6 +174,7 @@ bool aiVector2t::Equal(const aiVector2t& other, TReal epsilon) const { // ------------------------------------------------------------------------------------------------ template +inline aiVector2t& aiVector2t::operator= (TReal f) { x = y = f; return *this; @@ -160,6 +182,7 @@ aiVector2t& aiVector2t::operator= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { return aiVector2t(x*o.x,y*o.y); } @@ -168,65 +191,64 @@ const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ // symmetric addition template -inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x + v2.x, v1.y + v2.y); } // ------------------------------------------------------------------------------------------------ // symmetric subtraction template -inline aiVector2t operator - (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +aiVector2t operator - (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x - v2.x, v1.y - v2.y); } // ------------------------------------------------------------------------------------------------ // scalar product template -inline TReal operator * (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +TReal operator * (const aiVector2t& v1, const aiVector2t& v2) { return v1.x*v2.x + v1.y*v2.y; } // ------------------------------------------------------------------------------------------------ // scalar multiplication template -inline aiVector2t operator * ( TReal f, const aiVector2t& v) -{ +inline +aiVector2t operator * ( TReal f, const aiVector2t& v) { return aiVector2t( f*v.x, f*v.y); } // ------------------------------------------------------------------------------------------------ // and the other way around template -inline aiVector2t operator * ( const aiVector2t& v, TReal f) -{ +inline +aiVector2t operator * ( const aiVector2t& v, TReal f) { return aiVector2t( f*v.x, f*v.y); } // ------------------------------------------------------------------------------------------------ // scalar division template -inline aiVector2t operator / ( const aiVector2t& v, TReal f) -{ - +inline +aiVector2t operator / ( const aiVector2t& v, TReal f) { return v * (1/f); } // ------------------------------------------------------------------------------------------------ // vector division template -inline aiVector2t operator / ( const aiVector2t& v, const aiVector2t& v2) -{ +inline +aiVector2t operator / ( const aiVector2t& v, const aiVector2t& v2) { return aiVector2t(v.x / v2.x,v.y / v2.y); } // ------------------------------------------------------------------------------------------------ // vector negation template -inline aiVector2t operator - ( const aiVector2t& v) -{ +inline +aiVector2t operator - ( const aiVector2t& v) { return aiVector2t( -v.x, -v.y); } From 245b9b4bb1a1de421c0b95e92b187c04de8f7af8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:52:47 +0100 Subject: [PATCH 27/39] fix typo. --- include/assimp/vector2.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 97db2820c..1682a27ec 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -192,7 +192,7 @@ const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { // symmetric addition template inline -inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) { +aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x + v2.x, v1.y + v2.y); } From bef219a2d9cf40b8927c8bd24ac41ddd69c5aa2b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:59:23 +0100 Subject: [PATCH 28/39] fix access violation in vector2. --- include/assimp/vector2.h | 1 - include/assimp/vector2.inl | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index 564d1f8b5..df3c41024 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -85,7 +85,6 @@ public: const aiVector2t& operator /= (TReal f); TReal operator[](unsigned int i) const; - TReal& operator[](unsigned int i); bool operator== (const aiVector2t& other) const; bool operator!= (const aiVector2t& other) const; diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 1682a27ec..d6171955f 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -134,21 +134,6 @@ TReal aiVector2t::operator[](unsigned int i) const { return x; } -// ------------------------------------------------------------------------------------------------ -template -inline -TReal& aiVector2t::operator[](unsigned int i) { - switch (i) { - case 0: - return x; - case 1: - return y; - default: - break; - } - return x; -} - // ------------------------------------------------------------------------------------------------ template inline From dec3e2ba42e60be8c4ae3ba2a2f08d32ead77d51 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 18:06:28 +0100 Subject: [PATCH 29/39] XGLLoader: fix const issue when seeting vec2. --- code/XGLLoader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 8ef91afac..97fe4fbd5 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -904,12 +904,14 @@ aiVector2D XGLImporter::ReadVec2() } const char* s = m_reader->getNodeData(); - for(int i = 0; i < 2; ++i) { + ai_real v[2]; + for(int i = 0; i < 2; ++i) { if(!SkipSpaces(&s)) { LogError("unexpected EOL, failed to parse vec2"); return vec; } - vec[i] = fast_atof(&s); + + v[i] = fast_atof(&s); SkipSpaces(&s); if (i != 1 && *s != ',') { @@ -918,6 +920,8 @@ aiVector2D XGLImporter::ReadVec2() } ++s; } + vec.x = v[0]; + vex.y = v[1]; return vec; } From 5e63ba9a9d762f311e2fd1b9222ceca033abbcee Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 18:10:42 +0100 Subject: [PATCH 30/39] typo. --- code/XGLLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 97fe4fbd5..809936099 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -921,7 +921,7 @@ aiVector2D XGLImporter::ReadVec2() ++s; } vec.x = v[0]; - vex.y = v[1]; + vec.y = v[1]; return vec; } From 32e5e3a5764cbce871a11c4d9ecf58c75bac328e Mon Sep 17 00:00:00 2001 From: Alexis Breust Date: Fri, 15 Dec 2017 15:40:31 +0100 Subject: [PATCH 31/39] Forgot to uncomment isBinary --- code/glTF2Exporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 82b95195f..22ceb57d2 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -88,7 +88,7 @@ namespace Assimp { } // end of namespace Assimp glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene, - const ExportProperties* pProperties, bool /*isBinary*/) + const ExportProperties* pProperties, bool isBinary) : mFilename(filename) , mIOSystem(pIOSystem) , mProperties(pProperties) From 379562055b8061480e44a56354bb778c8e5449a7 Mon Sep 17 00:00:00 2001 From: Tommy Date: Fri, 15 Dec 2017 23:18:45 +0100 Subject: [PATCH 32/39] Fix incorrect NO_GLTF_IMPORTER define name in glTFExporter.h --- code/glTFExporter.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/glTFExporter.h b/code/glTFExporter.h index c813fff44..752072604 100644 --- a/code/glTFExporter.h +++ b/code/glTFExporter.h @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_GLTFEXPORTER_H_INC #define AI_GLTFEXPORTER_H_INC -#ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER +#ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER #include #include @@ -113,6 +113,6 @@ namespace Assimp } -#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER +#endif // ASSIMP_BUILD_NO_GLTF_EXPORTER #endif // AI_GLTFEXPORTER_H_INC From 068d4aa4cbcd88f6f4313374a0e562424e534467 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 13 Dec 2017 10:55:32 +0200 Subject: [PATCH 33/39] Disable clang static analysis for now Travis updated to clang 5.0 and there are new issues. --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9265dfb38..0b8d2f328 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,9 +33,10 @@ env: matrix: include: - - os: linux - compiler: clang - env: ANALYZE=ON + # disabled until clang 5.0 analyzer issues are fixed + # - os: linux + # compiler: clang + # env: ANALYZE=ON - os: linux compiler: clang env: ASAN=ON From 276fc5f46609b9a81b0a4ad0a3a6020f1708b746 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 13 Dec 2017 11:27:05 +0200 Subject: [PATCH 34/39] Remove packed attribute from aiUVTransform It would cause a warning when removing packed from aiVector2 --- include/assimp/material.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/material.h b/include/assimp/material.h index a12e7d076..502b89746 100644 --- a/include/assimp/material.h +++ b/include/assimp/material.h @@ -491,7 +491,7 @@ struct aiUVTransform } #endif -} PACK_STRUCT; +}; #include "./Compiler/poppack1.h" From 45ad63f37353fc2e84bccfb9daf32fff6fb3cbf8 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 13 Dec 2017 11:27:44 +0200 Subject: [PATCH 35/39] Remove packed attribute from aiVector2 Returning a reference to a member of packed member is UB --- include/assimp/vector2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index 564d1f8b5..3b85fc22b 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -99,7 +99,7 @@ public: operator aiVector2t () const; TReal x, y; -} PACK_STRUCT; +}; typedef aiVector2t aiVector2D; From 87462165b5243a96ddf4e4d1725e16e4aac3af5c Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Wed, 13 Dec 2017 11:28:22 +0200 Subject: [PATCH 36/39] Fix bad pointer arithmetic in aiVector2 Trying to reference 'y' via pointer arithmetic on 'x' is UB --- include/assimp/vector2.inl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index 5ce13eece..fe3059ad5 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -114,13 +114,29 @@ const aiVector2t& aiVector2t::operator /= (TReal f) { // ------------------------------------------------------------------------------------------------ template TReal aiVector2t::operator[](unsigned int i) const { - return *(&x + i); + switch (i) { + case 0: + return x; + case 1: + return y; + default: + break; + } + return x; } // ------------------------------------------------------------------------------------------------ template TReal& aiVector2t::operator[](unsigned int i) { - return *(&x + i); + switch (i) { + case 0: + return x; + case 1: + return y; + default: + break; + } + return x; } // ------------------------------------------------------------------------------------------------ From 2f082340fc668cd8fef56232d64fa824ce2b325d Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 16 Dec 2017 14:57:59 +0200 Subject: [PATCH 37/39] MDLLoader: Add workaround for clang 5.0 build issue --- code/MDLLoader.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 2025d79b3..dc7b379ce 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -415,8 +415,14 @@ void MDLImporter::InternReadFile_Quake1( ) else { // get the first frame in the group +#if 1 + // FIXME: the cast is wrong and causea a warning on clang 5.0 + // disable thi code for now, fix it later + ai_assert(false && "Bad pointer cast"); +#else BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames; pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type); +#endif } BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + pcHeader->num_verts)); From 463dec5c7ed89088614c9f84acc61a9d5f987368 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 16 Dec 2017 15:19:53 +0200 Subject: [PATCH 38/39] Change StreamReader::IncPtr argument to signed Negative values are passed to it so it needs to be signed --- code/StreamReader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/StreamReader.h b/code/StreamReader.h index 6220de9a8..b70ee7eca 100644 --- a/code/StreamReader.h +++ b/code/StreamReader.h @@ -192,7 +192,7 @@ public: // --------------------------------------------------------------------- /** Increase the file pointer (relative seeking) */ - void IncPtr(size_t plus) { + void IncPtr(intptr_t plus) { current += plus; if (current > limit) { throw DeadlyImportError("End of file or read limit was reached"); From 47c422ea49b1bbbd51b7715d371926b7d305757c Mon Sep 17 00:00:00 2001 From: Tommy Date: Sun, 17 Dec 2017 16:40:09 +0100 Subject: [PATCH 39/39] Fix non-ascii encoding in comments in FBXMaterial.cpp. It looks like it was just saved with a wrong encoding, as these 0xB4 characters were in place of "'". Also converted tabs to spaces to match indent in the rest of the file. --- code/FBXMaterial.cpp | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/code/FBXMaterial.cpp b/code/FBXMaterial.cpp index a80f243ba..130993d28 100644 --- a/code/FBXMaterial.cpp +++ b/code/FBXMaterial.cpp @@ -291,40 +291,40 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std if(FileName) { fileName = ParseTokenAsString(GetRequiredToken(*FileName,0)); - } + } if(RelativeFilename) { relativeFileName = ParseTokenAsString(GetRequiredToken(*RelativeFilename,0)); } if(Content) { - //this field is ommited when the embedded texture is already loaded, let's ignore if itīs not found - try { - const Token& token = GetRequiredToken(*Content, 0); - const char* data = token.begin(); - if (!token.IsBinary()) { - DOMWarning("video content is not binary data, ignoring", &element); - } - else if (static_cast(token.end() - data) < 5) { - DOMError("binary data array is too short, need five (5) bytes for type signature and element count", &element); - } - else if (*data != 'R') { - DOMWarning("video content is not raw binary data, ignoring", &element); - } - else { - // read number of elements - uint32_t len = 0; - ::memcpy(&len, data + 1, sizeof(len)); - AI_SWAP4(len); + //this field is ommited when the embedded texture is already loaded, let's ignore if it's not found + try { + const Token& token = GetRequiredToken(*Content, 0); + const char* data = token.begin(); + if (!token.IsBinary()) { + DOMWarning("video content is not binary data, ignoring", &element); + } + else if (static_cast(token.end() - data) < 5) { + DOMError("binary data array is too short, need five (5) bytes for type signature and element count", &element); + } + else if (*data != 'R') { + DOMWarning("video content is not raw binary data, ignoring", &element); + } + else { + // read number of elements + uint32_t len = 0; + ::memcpy(&len, data + 1, sizeof(len)); + AI_SWAP4(len); - contentLength = len; + contentLength = len; - content = new uint8_t[len]; - ::memcpy(content, data + 5, len); - } - } catch (runtime_error runtimeError) { - //we donīt need the content data for contents that has already been loaded - } + content = new uint8_t[len]; + ::memcpy(content, data + 5, len); + } + } catch (runtime_error runtimeError) { + //we don't need the content data for contents that has already been loaded + } } props = GetPropertyTable(doc,"Video.FbxVideo",element,sc);