From b28bcc365c1ca1063c5df4f906f73dfb49603477 Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Wed, 24 Jan 2018 09:45:20 -0500 Subject: [PATCH 1/7] Interpret IndexAToDirect as Direct when the index element is missing Paint3D exports FBX like this, which is wrong, but could still support it --- code/FBXMeshGeometry.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/code/FBXMeshGeometry.cpp b/code/FBXMeshGeometry.cpp index 4868b3e72..99e1b1c5f 100644 --- a/code/FBXMeshGeometry.cpp +++ b/code/FBXMeshGeometry.cpp @@ -427,16 +427,19 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, const std::vector& mapping_offsets, const std::vector& mappings) { + bool isDirect = ReferenceInformationType == "Direct"; + bool isIndexToDirect = ReferenceInformationType == "IndexToDirect"; + // fallback to direct data if there is no index data element + if ( isIndexToDirect && !HasElement( source, indexDataElementName ) ) { + isDirect = true; + isIndexToDirect = false; + } // handle permutations of Mapping and Reference type - it would be nice to // deal with this more elegantly and with less redundancy, but right // now it seems unavoidable. - if (MappingInformationType == "ByVertice" && ReferenceInformationType == "Direct") { - if ( !HasElement( source, indexDataElementName ) ) { - return; - } - + if (MappingInformationType == "ByVertice" && isDirect) { std::vector tempData; ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); @@ -449,14 +452,11 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, } } } - else if (MappingInformationType == "ByVertice" && ReferenceInformationType == "IndexToDirect") { + else if (MappingInformationType == "ByVertice" && isIndexToDirect) { std::vector tempData; ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); data_out.resize(vertex_count); - if ( !HasElement( source, indexDataElementName ) ) { - return; - } std::vector uvIndices; ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName)); @@ -471,7 +471,7 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, } } } - else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "Direct") { + else if (MappingInformationType == "ByPolygonVertex" && isDirect) { std::vector tempData; ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); @@ -484,7 +484,7 @@ void ResolveVertexDataArray(std::vector& data_out, const Scope& source, data_out.swap(tempData); } - else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "IndexToDirect") { + else if (MappingInformationType == "ByPolygonVertex" && isIndexToDirect) { std::vector tempData; ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName)); From 4736160b793ed86840cb07c156a469516c1c92b4 Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Tue, 6 Feb 2018 22:36:37 +0100 Subject: [PATCH 2/7] Update BlenderDNA.h --- code/BlenderDNA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/BlenderDNA.h b/code/BlenderDNA.h index 932784e9f..43c9d2d82 100644 --- a/code/BlenderDNA.h +++ b/code/BlenderDNA.h @@ -204,7 +204,7 @@ enum ErrorPolicy { // ------------------------------------------------------------------------------- /** Represents a data structure in a BLEND file. A Structure defines n fields - * and their locatios and encodings the input stream. Usually, every + * and their locations and encodings the input stream. Usually, every * Structure instance pertains to one equally-named data structure in the * BlenderScene.h header. This class defines various utilities to map a * binary `blob` read from the file to such a structure instance with From f00d450d254d5ba56fdad4bf004127847ee6b551 Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Sun, 11 Feb 2018 17:43:49 +0100 Subject: [PATCH 3/7] Update BlenderDNA.inl --- code/BlenderDNA.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/BlenderDNA.inl b/code/BlenderDNA.inl index de85815cc..c6a3779b1 100644 --- a/code/BlenderDNA.inl +++ b/code/BlenderDNA.inl @@ -501,7 +501,7 @@ const FileBlockHead* Structure :: LocateFileBlockForAddress(const Pointer & ptrv { // the file blocks appear in list sorted by // with ascending base addresses so we can run a - // binary search to locate the pointee quickly. + // binary search to locate the pointer quickly. // NOTE: Blender seems to distinguish between side-by-side // data (stored in the same data block) and far pointers, From 12999050262d8a6213cf6b1f136a11fa80f57066 Mon Sep 17 00:00:00 2001 From: mbuchner Date: Mon, 12 Feb 2018 11:20:03 +0100 Subject: [PATCH 4/7] Make FileSystemFilter forward all virtual functions to wrapped IOSystem instance This makes it possible to override those functions. Previously the default implementation was always used. Fixes #1773 --- code/FileSystemFilter.h | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/code/FileSystemFilter.h b/code/FileSystemFilter.h index 0fabb41dd..10b18bd78 100644 --- a/code/FileSystemFilter.h +++ b/code/FileSystemFilter.h @@ -168,6 +168,55 @@ public: return wrapped->ComparePaths (one,second); } + // ------------------------------------------------------------------- + /** Pushes a new directory onto the directory stack. */ + bool PushDirectory(const std::string &path) + { + return wrapped->PushDirectory(path); + } + + // ------------------------------------------------------------------- + /** Returns the top directory from the stack. */ + const std::string &CurrentDirectory() const + { + return wrapped->CurrentDirectory(); + } + + // ------------------------------------------------------------------- + /** Returns the number of directories stored on the stack. */ + size_t StackSize() const + { + return wrapped->StackSize(); + } + + // ------------------------------------------------------------------- + /** Pops the top directory from the stack. */ + bool PopDirectory() + { + return wrapped->PopDirectory(); + } + + // ------------------------------------------------------------------- + /** Creates an new directory at the given path. */ + bool CreateDirectory(const std::string &path) + { + return wrapped->CreateDirectory(path); + } + + // ------------------------------------------------------------------- + /** Will change the current directory to the given path. */ + bool ChangeDirectory(const std::string &path) + { + return wrapped->ChangeDirectory(path); + } + + // ------------------------------------------------------------------- + /** Delete file. */ + bool DeleteFile(const std::string &file) + { + return wrapped->DeleteFile(file); + } + private: // ------------------------------------------------------------------- From 8a4fd2f9477b6d624f9f94f2f1367c84e81e5a5d Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Mon, 12 Feb 2018 21:51:40 +0100 Subject: [PATCH 5/7] globalScale process not registered --- code/PostStepRegistry.cpp | 9 +++++++-- code/ScaleProcess.cpp | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/PostStepRegistry.cpp b/code/PostStepRegistry.cpp index 49f5d7375..2a5e211c1 100644 --- a/code/PostStepRegistry.cpp +++ b/code/PostStepRegistry.cpp @@ -125,6 +125,9 @@ corresponding preprocessor flag to selectively disable steps. #ifndef ASSIMP_BUILD_NO_DEBONE_PROCESS # include "DeboneProcess.h" #endif +#if (!defined ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS) +# include "ScaleProcess.h" +#endif namespace Assimp { @@ -136,7 +139,7 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out) // of sequence it is executed. Steps that are added here are not // validated - as RegisterPPStep() does - all dependencies must be given. // ---------------------------------------------------------------------------- - out.reserve(30); + out.reserve(31); #if (!defined ASSIMP_BUILD_NO_MAKELEFTHANDED_PROCESS) out.push_back( new MakeLeftHandedProcess()); #endif @@ -197,7 +200,9 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out) #if (!defined ASSIMP_BUILD_NO_GENFACENORMALS_PROCESS) out.push_back( new GenFaceNormalsProcess()); #endif - +#if (!defined ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS) + out.push_back( new ScaleProcess()); +#endif // ......................................................................... // DON'T change the order of these five .. // XXX this is actually a design weakness that dates back to the time diff --git a/code/ScaleProcess.cpp b/code/ScaleProcess.cpp index ef7357b68..0f60fbdb4 100644 --- a/code/ScaleProcess.cpp +++ b/code/ScaleProcess.cpp @@ -39,6 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ +#ifndef ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS + #include "ScaleProcess.h" #include @@ -104,3 +106,5 @@ void ScaleProcess::applyScaling( aiNode *currentNode ) { } } // Namespace Assimp + +#endif // !! ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS From ccbcaa2ee8482c196e6d7cb1a86b6f75d34c8ea0 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 13 Feb 2018 20:36:22 +0100 Subject: [PATCH 6/7] fix some static-analysis findings. --- code/FindInstancesProcess.h | 14 +++++----- code/OpenGEXImporter.cpp | 27 ++++++++++-------- code/SceneCombiner.cpp | 47 ++++++++++++++++---------------- code/SpatialSort.cpp | 2 +- code/VertexTriangleAdjacency.cpp | 15 ++++------ code/VertexTriangleAdjacency.h | 29 ++++++-------------- include/assimp/IOStreamBuffer.h | 4 +-- include/assimp/SGSpatialSort.h | 2 +- 8 files changed, 65 insertions(+), 75 deletions(-) diff --git a/code/FindInstancesProcess.h b/code/FindInstancesProcess.h index 2ef6c1ca7..fb2ac6eb6 100644 --- a/code/FindInstancesProcess.h +++ b/code/FindInstancesProcess.h @@ -60,9 +60,9 @@ namespace Assimp { * @param in Input mesh * @return Hash. */ -inline uint64_t GetMeshHash(aiMesh* in) -{ - ai_assert(NULL != in); +inline +uint64_t GetMeshHash(aiMesh* in) { + ai_assert(nullptr != in); // ... get an unique value representing the vertex format of the mesh const unsigned int fhash = GetMeshVFormatUnique(in); @@ -78,14 +78,14 @@ inline uint64_t GetMeshHash(aiMesh* in) /** @brief Perform a component-wise comparison of two arrays * * @param first First array - * @param second Second aray + * @param second Second array * @param size Size of both arrays * @param e Epsilon * @return true if the arrays are identical */ -inline bool CompareArrays(const aiVector3D* first, const aiVector3D* second, - unsigned int size, float e) -{ +inline +bool CompareArrays(const aiVector3D* first, const aiVector3D* second, + unsigned int size, float e) { for (const aiVector3D* end = first+size; first != end; ++first,++second) { if ( (*first - *second).SquareLength() >= e) return false; diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index 43c92c4f5..652ba0f98 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -731,17 +731,22 @@ enum MeshAttribute { TexCoord }; +static const std::string PosToken = "position"; +static const std::string ColToken = "color"; +static const std::string NormalToken = "normal"; +static const std::string TexCoordToken = "texcoord"; + //------------------------------------------------------------------------------------------------ static MeshAttribute getAttributeByName( const char *attribName ) { ai_assert( nullptr != attribName ); - if ( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) { + if ( 0 == strncmp( PosToken.c_str(), attribName, PosToken.size() ) ) { return Position; - } else if ( 0 == strncmp( "color", attribName, strlen( "color" ) ) ) { + } else if ( 0 == strncmp( ColToken.c_str(), attribName, ColToken.size() ) ) { return Color; - } else if( 0 == strncmp( "normal", attribName, strlen( "normal" ) ) ) { + } else if( 0 == strncmp( NormalToken.c_str(), attribName, NormalToken.size() ) ) { return Normal; - } else if( 0 == strncmp( "texcoord", attribName, strlen( "texcoord" ) ) ) { + } else if( 0 == strncmp( TexCoordToken.c_str(), attribName, TexCoordToken.size() ) ) { return TexCoord; } @@ -1098,14 +1103,12 @@ void OpenGEXImporter::handleParamNode( ODDLParser::DDLNode *node, aiScene * /*pS return; } const float floatVal( val->getFloat() ); - if ( prop->m_value != nullptr ) { - if ( 0 == ASSIMP_strincmp( "fov", prop->m_value->getString(), 3 ) ) { - m_currentCamera->mHorizontalFOV = floatVal; - } else if ( 0 == ASSIMP_strincmp( "near", prop->m_value->getString(), 3 ) ) { - m_currentCamera->mClipPlaneNear = floatVal; - } else if ( 0 == ASSIMP_strincmp( "far", prop->m_value->getString(), 3 ) ) { - m_currentCamera->mClipPlaneFar = floatVal; - } + if ( 0 == ASSIMP_strincmp( "fov", prop->m_value->getString(), 3 ) ) { + m_currentCamera->mHorizontalFOV = floatVal; + } else if ( 0 == ASSIMP_strincmp( "near", prop->m_value->getString(), 4 ) ) { + m_currentCamera->mClipPlaneNear = floatVal; + } else if ( 0 == ASSIMP_strincmp( "far", prop->m_value->getString(), 3 ) ) { + m_currentCamera->mClipPlaneFar = floatVal; } } } diff --git a/code/SceneCombiner.cpp b/code/SceneCombiner.cpp index 30722618f..8647bd1ba 100644 --- a/code/SceneCombiner.cpp +++ b/code/SceneCombiner.cpp @@ -1256,29 +1256,30 @@ void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src) { aiMetadataEntry& out = dest->mValues[i]; out.mType = in.mType; switch (dest->mValues[i].mType) { - case AI_BOOL: - out.mData = new bool(*static_cast(in.mData)); - break; - case AI_INT32: - out.mData = new int32_t(*static_cast(in.mData)); - break; - case AI_UINT64: - out.mData = new uint64_t(*static_cast(in.mData)); - break; - case AI_FLOAT: - out.mData = new float(*static_cast(in.mData)); - break; - case AI_DOUBLE: - out.mData = new double(*static_cast(in.mData)); - break; - case AI_AISTRING: - out.mData = new aiString(*static_cast(in.mData)); - break; - case AI_AIVECTOR3D: - out.mData = new aiVector3D(*static_cast(in.mData)); - break; - default: - ai_assert(false); + case AI_BOOL: + out.mData = new bool(*static_cast(in.mData)); + break; + case AI_INT32: + out.mData = new int32_t(*static_cast(in.mData)); + break; + case AI_UINT64: + out.mData = new uint64_t(*static_cast(in.mData)); + break; + case AI_FLOAT: + out.mData = new float(*static_cast(in.mData)); + break; + case AI_DOUBLE: + out.mData = new double(*static_cast(in.mData)); + break; + case AI_AISTRING: + out.mData = new aiString(*static_cast(in.mData)); + break; + case AI_AIVECTOR3D: + out.mData = new aiVector3D(*static_cast(in.mData)); + break; + default: + ai_assert(false); + break; } } } diff --git a/code/SpatialSort.cpp b/code/SpatialSort.cpp index 010cad7c1..e6ffeb260 100644 --- a/code/SpatialSort.cpp +++ b/code/SpatialSort.cpp @@ -294,7 +294,7 @@ void SpatialSort::FindIdenticalPositions( const aiVector3D& pPosition, index++; // Now start iterating from there until the first position lays outside of the distance range. - // Add all positions inside the distance range within the tolerance to the result aray + // Add all positions inside the distance range within the tolerance to the result array std::vector::const_iterator it = mPositions.begin() + index; while( ToBinary(it->mDistance) < maxDistBinary) { diff --git a/code/VertexTriangleAdjacency.cpp b/code/VertexTriangleAdjacency.cpp index 022d5d902..5886ca372 100644 --- a/code/VertexTriangleAdjacency.cpp +++ b/code/VertexTriangleAdjacency.cpp @@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "VertexTriangleAdjacency.h" #include - using namespace Assimp; // ------------------------------------------------------------------------------------------------ @@ -60,8 +59,8 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces, // compute the number of referenced vertices if it wasn't specified by the caller const aiFace* const pcFaceEnd = pcFaces + iNumFaces; if (!iNumVertices) { - for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) { + ai_assert( nullptr != pcFace ); ai_assert(3 == pcFace->mNumIndices); iNumVertices = std::max(iNumVertices,pcFace->mIndices[0]); iNumVertices = std::max(iNumVertices,pcFace->mIndices[1]); @@ -69,19 +68,18 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces, } } - this->iNumVertices = iNumVertices; + mNumVertices = iNumVertices; unsigned int* pi; // allocate storage if (bComputeNumTriangles) { pi = mLiveTriangles = new unsigned int[iNumVertices+1]; - memset(mLiveTriangles,0,sizeof(unsigned int)*(iNumVertices+1)); + ::memset(mLiveTriangles,0,sizeof(unsigned int)*(iNumVertices+1)); mOffsetTable = new unsigned int[iNumVertices+2]+1; - } - else { + } else { pi = mOffsetTable = new unsigned int[iNumVertices+2]+1; - memset(mOffsetTable,0,sizeof(unsigned int)*(iNumVertices+1)); + ::memset(mOffsetTable,0,sizeof(unsigned int)*(iNumVertices+1)); mLiveTriangles = NULL; // important, otherwise the d'tor would crash } @@ -90,8 +88,7 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces, *piEnd++ = 0u; // first pass: compute the number of faces referencing each vertex - for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) - { + for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) { pi[pcFace->mIndices[0]]++; pi[pcFace->mIndices[1]]++; pi[pcFace->mIndices[2]]++; diff --git a/code/VertexTriangleAdjacency.h b/code/VertexTriangleAdjacency.h index 566783835..23624a5be 100644 --- a/code/VertexTriangleAdjacency.h +++ b/code/VertexTriangleAdjacency.h @@ -60,10 +60,8 @@ namespace Assimp { * @note Although it is called #VertexTriangleAdjacency, the current version does also * support arbitrary polygons. */ // -------------------------------------------------------------------------------------------- -class ASSIMP_API VertexTriangleAdjacency -{ +class ASSIMP_API VertexTriangleAdjacency { public: - // ---------------------------------------------------------------------------- /** @brief Construction from an existing index buffer * @param pcFaces Index buffer @@ -77,39 +75,30 @@ public: unsigned int iNumVertices = 0, bool bComputeNumTriangles = true); - // ---------------------------------------------------------------------------- /** @brief Destructor */ ~VertexTriangleAdjacency(); - -public: - // ---------------------------------------------------------------------------- /** @brief Get all triangles adjacent to a vertex * @param iVertIndex Index of the vertex * @return A pointer to the adjacency list. */ - unsigned int* GetAdjacentTriangles(unsigned int iVertIndex) const - { - ai_assert(iVertIndex < iNumVertices); + unsigned int* GetAdjacentTriangles(unsigned int iVertIndex) const { + ai_assert(iVertIndex < mNumVertices); return &mAdjacencyTable[ mOffsetTable[iVertIndex]]; } - // ---------------------------------------------------------------------------- /** @brief Get the number of triangles that are referenced by * a vertex. This function returns a reference that can be modified * @param iVertIndex Index of the vertex * @return Number of referenced triangles */ - unsigned int& GetNumTrianglesPtr(unsigned int iVertIndex) - { - ai_assert(iVertIndex < iNumVertices && NULL != mLiveTriangles); + unsigned int& GetNumTrianglesPtr(unsigned int iVertIndex) { + ai_assert( iVertIndex < mNumVertices ); + ai_assert( nullptr != mLiveTriangles ); return mLiveTriangles[iVertIndex]; } - -public: - //! Offset table unsigned int* mOffsetTable; @@ -120,9 +109,9 @@ public: unsigned int* mLiveTriangles; //! Debug: Number of referenced vertices - unsigned int iNumVertices; - + unsigned int mNumVertices; }; -} + +} //! ns Assimp #endif // !! AI_VTADJACENCY_H_INC diff --git a/include/assimp/IOStreamBuffer.h b/include/assimp/IOStreamBuffer.h index a503b3874..fdc339062 100644 --- a/include/assimp/IOStreamBuffer.h +++ b/include/assimp/IOStreamBuffer.h @@ -248,9 +248,9 @@ bool IOStreamBuffer::getNextDataLine( std::vector &buffer, T continuationT } } - bool continuationFound( false ), endOfDataLine( false ); + bool continuationFound( false ); size_t i = 0; - while ( !endOfDataLine ) { + for( ;; ) { if ( continuationToken == m_cache[ m_cachePos ] ) { continuationFound = true; ++m_cachePos; diff --git a/include/assimp/SGSpatialSort.h b/include/assimp/SGSpatialSort.h index d8b4b418b..203e32512 100644 --- a/include/assimp/SGSpatialSort.h +++ b/include/assimp/SGSpatialSort.h @@ -123,7 +123,7 @@ protected: Entry() { /** intentionally not initialized.*/ } Entry( unsigned int pIndex, const aiVector3D& pPosition, float pDistance,uint32_t pSG) - : + : mIndex( pIndex), mPosition( pPosition), mSmoothGroups (pSG), From 58436068e7e08e496a1d415461de706a33f7832f Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Fri, 16 Feb 2018 22:16:10 +0100 Subject: [PATCH 7/7] Update BlenderScene.cpp --- code/BlenderScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/BlenderScene.cpp b/code/BlenderScene.cpp index 0e1dec7f3..e4373909e 100644 --- a/code/BlenderScene.cpp +++ b/code/BlenderScene.cpp @@ -116,7 +116,7 @@ template <> void Structure :: Convert ( ReadField(temp,"projy",db); dest.projy = static_cast(temp); ReadField(temp,"projz",db); - dest.projx = static_cast(temp); + dest.projz = static_cast(temp); ReadField(dest.mapping,"mapping",db); ReadFieldArray(dest.ofs,"ofs",db); ReadFieldArray(dest.size,"size",db);