diff --git a/code/AssetLib/3DS/3DSHelper.h b/code/AssetLib/3DS/3DSHelper.h index 06c36bfeb..2279d105c 100644 --- a/code/AssetLib/3DS/3DSHelper.h +++ b/code/AssetLib/3DS/3DSHelper.h @@ -397,10 +397,6 @@ struct Material { Material(const Material &other) = default; - Material(Material &&other) AI_NO_EXCEPT = default; - - Material &operator=(Material &&other) AI_NO_EXCEPT = default; - virtual ~Material() = default; //! Name of the material diff --git a/code/AssetLib/X3D/X3DExporter.hpp b/code/AssetLib/X3D/X3DExporter.hpp index e77aa6877..babf552dd 100644 --- a/code/AssetLib/X3D/X3DExporter.hpp +++ b/code/AssetLib/X3D/X3DExporter.hpp @@ -58,8 +58,6 @@ class X3DExporter { Value(value) { // empty } - - SAttribute(SAttribute &&rhs) AI_NO_EXCEPT = default; }; /***********************************************/ diff --git a/code/Geometry/GeometryUtils.cpp b/code/Geometry/GeometryUtils.cpp index ab735aa6e..92a3aa853 100644 --- a/code/Geometry/GeometryUtils.cpp +++ b/code/Geometry/GeometryUtils.cpp @@ -76,4 +76,17 @@ ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh return area; } +// ------------------------------------------------------------------------------------------------ +// Check whether a ray intersects a plane and find the intersection point +bool GeometryUtils::PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, + const aiVector3D& planeNormal, aiVector3D& pos) { + const ai_real b = planeNormal * (planePos - ray.pos); + ai_real h = ray.dir * planeNormal; + if ((h < 10e-5 && h > -10e-5) || (h = b/h) < 0) + return false; + + pos = ray.pos + (ray.dir * h); + return true; +} + } // namespace Assimp diff --git a/code/Geometry/GeometryUtils.h b/code/Geometry/GeometryUtils.h index ab49380de..bd2038f78 100644 --- a/code/Geometry/GeometryUtils.h +++ b/code/Geometry/GeometryUtils.h @@ -62,6 +62,8 @@ public: /// @param mesh The mesh containing the face /// @return The area. static ai_real calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh ); + + static bool PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, const aiVector3D& planeNormal, aiVector3D& pos); }; } // namespace Assimp diff --git a/code/PostProcessing/ArmaturePopulate.cpp b/code/PostProcessing/ArmaturePopulate.cpp index a05cd91e9..a29735205 100644 --- a/code/PostProcessing/ArmaturePopulate.cpp +++ b/code/PostProcessing/ArmaturePopulate.cpp @@ -47,11 +47,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -/// The default class constructor. -ArmaturePopulate::ArmaturePopulate() = default; +static bool IsBoneNode(const aiString &bone_name, std::vector &bones) { + for (aiBone *bone : bones) { + if (bone->mName == bone_name) { + return true; + } + } -/// The class destructor. -ArmaturePopulate::~ArmaturePopulate() = default; + return false; +} bool ArmaturePopulate::IsActive(unsigned int pFlags) const { return (pFlags & aiProcess_PopulateArmatureData) != 0; @@ -78,9 +82,8 @@ void ArmaturePopulate::Execute(aiScene *out) { aiBone *bone = kvp.first; aiNode *bone_node = kvp.second; ASSIMP_LOG_VERBOSE_DEBUG("active node lookup: ", bone->mName.C_Str()); + // lcl transform grab - done in generate_nodes :) - - // bone->mOffsetMatrix = bone_node->mTransformation; aiNode *armature = GetArmatureRoot(bone_node, bones); ai_assert(armature); @@ -212,18 +215,6 @@ aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node, return nullptr; } -// Simple IsBoneNode check if this could be a bone -bool ArmaturePopulate::IsBoneNode(const aiString &bone_name, - std::vector &bones) { - for (aiBone *bone : bones) { - if (bone->mName == bone_name) { - return true; - } - } - - return false; -} - // Pop this node by name from the stack if found // Used in multiple armature situations with duplicate node / bone names // Known flaw: cannot have nodes with bone names, will be fixed in later release diff --git a/code/PostProcessing/ArmaturePopulate.h b/code/PostProcessing/ArmaturePopulate.h index 530932f48..83cbf8cf7 100644 --- a/code/PostProcessing/ArmaturePopulate.h +++ b/code/PostProcessing/ArmaturePopulate.h @@ -69,10 +69,10 @@ namespace Assimp { class ASSIMP_API ArmaturePopulate : public BaseProcess { public: /// The default class constructor. - ArmaturePopulate(); + ArmaturePopulate() = default; /// The class destructor. - virtual ~ArmaturePopulate(); + virtual ~ArmaturePopulate() = default; /// Overwritten, @see BaseProcess virtual bool IsActive( unsigned int pFlags ) const; @@ -86,9 +86,6 @@ public: static aiNode *GetArmatureRoot(aiNode *bone_node, std::vector &bone_list); - static bool IsBoneNode(const aiString &bone_name, - std::vector &bones); - static aiNode *GetNodeFromStack(const aiString &node_name, std::vector &nodes); @@ -108,5 +105,4 @@ public: } // Namespace Assimp - #endif // SCALE_PROCESS_H_ diff --git a/code/PostProcessing/ComputeUVMappingProcess.cpp b/code/PostProcessing/ComputeUVMappingProcess.cpp index a5472668b..e81f63d42 100644 --- a/code/PostProcessing/ComputeUVMappingProcess.cpp +++ b/code/PostProcessing/ComputeUVMappingProcess.cpp @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -42,10 +41,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file GenUVCoords step */ - #include "ComputeUVMappingProcess.h" #include "ProcessHelper.h" #include +#include "Geometry/GeometryUtils.h" using namespace Assimp; @@ -59,31 +58,17 @@ namespace { // ------------------------------------------------------------------------------------------------ // Returns whether the processing step is present in the given flag field. -bool ComputeUVMappingProcess::IsActive( unsigned int pFlags) const -{ +bool ComputeUVMappingProcess::IsActive( unsigned int pFlags) const { return (pFlags & aiProcess_GenUVCoords) != 0; } -// ------------------------------------------------------------------------------------------------ -// Check whether a ray intersects a plane and find the intersection point -inline bool PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, - const aiVector3D& planeNormal, aiVector3D& pos) -{ - const ai_real b = planeNormal * (planePos - ray.pos); - ai_real h = ray.dir * planeNormal; - if ((h < 10e-5 && h > -10e-5) || (h = b/h) < 0) - return false; - - pos = ray.pos + (ray.dir * h); - return true; -} - // ------------------------------------------------------------------------------------------------ // Find the first empty UV channel in a mesh -inline unsigned int FindEmptyUVChannel (aiMesh* mesh) -{ +inline unsigned int FindEmptyUVChannel (aiMesh* mesh) { for (unsigned int m = 0; m < AI_MAX_NUMBER_OF_TEXTURECOORDS;++m) - if (!mesh->mTextureCoords[m])return m; + if (!mesh->mTextureCoords[m]) { + return m; + } ASSIMP_LOG_ERROR("Unable to compute UV coordinates, no free UV slot found"); return UINT_MAX; @@ -91,8 +76,7 @@ inline unsigned int FindEmptyUVChannel (aiMesh* mesh) // ------------------------------------------------------------------------------------------------ // Try to remove UV seams -void RemoveUVSeams (aiMesh* mesh, aiVector3D* out) -{ +void RemoveUVSeams (aiMesh* mesh, aiVector3D* out) { // TODO: just a very rough algorithm. I think it could be done // much easier, but I don't know how and am currently too tired to // to think about a better solution. @@ -103,10 +87,11 @@ void RemoveUVSeams (aiMesh* mesh, aiVector3D* out) const static ai_real LOWER_EPSILON = ai_real( 10e-3 ); const static ai_real UPPER_EPSILON = ai_real( 1.0-10e-3 ); - for (unsigned int fidx = 0; fidx < mesh->mNumFaces;++fidx) - { + for (unsigned int fidx = 0; fidx < mesh->mNumFaces;++fidx) { const aiFace& face = mesh->mFaces[fidx]; - if (face.mNumIndices < 3) continue; // triangles and polygons only, please + if (face.mNumIndices < 3) { + continue; // triangles and polygons only, please + } unsigned int smallV = face.mNumIndices, large = smallV; bool zero = false, one = false, round_to_zero = false; diff --git a/code/PostProcessing/ConvertToLHProcess.cpp b/code/PostProcessing/ConvertToLHProcess.cpp index 08e3fe48a..e67bf030f 100644 --- a/code/PostProcessing/ConvertToLHProcess.cpp +++ b/code/PostProcessing/ConvertToLHProcess.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -219,13 +217,6 @@ void MakeLeftHandedProcess::ProcessAnimation(aiNodeAnim *pAnim) { // rotation keys for (unsigned int a = 0; a < pAnim->mNumRotationKeys; a++) { - /* That's the safe version, but the float errors add up. So we try the short version instead - aiMatrix3x3 rotmat = pAnim->mRotationKeys[a].mValue.GetMatrix(); - rotmat.a3 = -rotmat.a3; rotmat.b3 = -rotmat.b3; - rotmat.c1 = -rotmat.c1; rotmat.c2 = -rotmat.c2; - aiQuaternion rotquat( rotmat); - pAnim->mRotationKeys[a].mValue = rotquat; - */ pAnim->mRotationKeys[a].mValue.x *= -1.0f; pAnim->mRotationKeys[a].mValue.y *= -1.0f; } diff --git a/code/PostProcessing/DeboneProcess.cpp b/code/PostProcessing/DeboneProcess.cpp index 2a8499dc5..e91196ce2 100644 --- a/code/PostProcessing/DeboneProcess.cpp +++ b/code/PostProcessing/DeboneProcess.cpp @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -87,7 +86,7 @@ void DeboneProcess::Execute( aiScene* pScene) { if(!!mNumBonesCanDoWithout && (!mAllOrNone||mNumBonesCanDoWithout==mNumBones)) { for(unsigned int a = 0; a < pScene->mNumMeshes; a++) { if(splitList[a]) { - numSplits++; + ++numSplits; } } } @@ -119,8 +118,8 @@ void DeboneProcess::Execute( aiScene* pScene) { aiNode *theNode = find ? pScene->mRootNode->FindNode(*find) : nullptr; std::pair push_pair(static_cast(meshes.size()),theNode); - mSubMeshIndices[a].push_back(push_pair); - meshes.push_back(newMeshes[b].first); + mSubMeshIndices[a].emplace_back(push_pair); + meshes.emplace_back(newMeshes[b].first); out+=newMeshes[b].first->mNumBones; } @@ -360,9 +359,7 @@ void DeboneProcess::UpdateNode(aiNode* pNode) const { unsigned int m = static_cast(pNode->mNumMeshes), n = static_cast(mSubMeshIndices.size()); // first pass, look for meshes which have not moved - for(unsigned int a=0;amMeshes[a]; const std::vector< std::pair< unsigned int,aiNode* > > &subMeshes = mSubMeshIndices[srcIndex]; unsigned int nSubmeshes = static_cast(subMeshes.size()); @@ -376,8 +373,7 @@ void DeboneProcess::UpdateNode(aiNode* pNode) const { // second pass, collect deboned meshes - for(unsigned int a=0;a > &subMeshes = mSubMeshIndices[a]; unsigned int nSubmeshes = static_cast(subMeshes.size()); diff --git a/code/PostProcessing/FindDegenerates.cpp b/code/PostProcessing/FindDegenerates.cpp index 5874c17d2..87ee75601 100644 --- a/code/PostProcessing/FindDegenerates.cpp +++ b/code/PostProcessing/FindDegenerates.cpp @@ -236,8 +236,7 @@ evil_jump_outside: face_src.mNumIndices = 0; face_src.mIndices = nullptr; } - } - else { + } else { // Otherwise delete it if we don't need this face delete[] face_src.mIndices; face_src.mIndices = nullptr; diff --git a/code/PostProcessing/RemoveVCProcess.cpp b/code/PostProcessing/RemoveVCProcess.cpp index 35047dc0a..bcad65423 100644 --- a/code/PostProcessing/RemoveVCProcess.cpp +++ b/code/PostProcessing/RemoveVCProcess.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -74,63 +72,6 @@ inline void ArrayDelete(T **&in, unsigned int &num) { num = 0; } -#if 0 -// ------------------------------------------------------------------------------------------------ -// Updates the node graph - removes all nodes which have the "remove" flag set and the -// "don't remove" flag not set. Nodes with meshes are never deleted. -bool UpdateNodeGraph(aiNode* node,std::list& childsOfParent,bool root) -{ - bool b = false; - - std::list mine; - for (unsigned int i = 0; i < node->mNumChildren;++i) - { - if(UpdateNodeGraph(node->mChildren[i],mine,false)) - b = true; - } - - // somewhat tricky ... mNumMeshes must be originally 0 and MSB2 may not be set, - // so we can do a simple comparison against MSB here - if (!root && AI_RC_UINT_MSB == node->mNumMeshes ) - { - // this node needs to be removed - if(node->mNumChildren) - { - childsOfParent.insert(childsOfParent.end(),mine.begin(),mine.end()); - - // set all children to nullptr to make sure they are not deleted when we delete ourself - for (unsigned int i = 0; i < node->mNumChildren;++i) - node->mChildren[i] = nullptr; - } - b = true; - delete node; - } - else - { - AI_RC_UNMASK(node->mNumMeshes); - childsOfParent.push_back(node); - - if (b) - { - // reallocate the array of our children here - node->mNumChildren = (unsigned int)mine.size(); - aiNode** const children = new aiNode*[mine.size()]; - aiNode** ptr = children; - - for (std::list::iterator it = mine.begin(), end = mine.end(); - it != end; ++it) - { - *ptr++ = *it; - } - delete[] node->mChildren; - node->mChildren = children; - return false; - } - } - return b; -} -#endif - // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. void RemoveVCProcess::Execute(aiScene *pScene) { diff --git a/code/PostProcessing/ScaleProcess.cpp b/code/PostProcessing/ScaleProcess.cpp index 665f28a7e..00df07090 100644 --- a/code/PostProcessing/ScaleProcess.cpp +++ b/code/PostProcessing/ScaleProcess.cpp @@ -86,9 +86,9 @@ void ScaleProcess::Execute( aiScene* pScene ) { return; // nothing to scale } - ai_assert( mScale != 0 ); - ai_assert( nullptr != pScene ); - ai_assert( nullptr != pScene->mRootNode ); + ai_assert(mScale != 0 ); + ai_assert(nullptr != pScene ); + ai_assert(nullptr != pScene->mRootNode ); if ( nullptr == pScene ) { return; @@ -140,7 +140,7 @@ void ScaleProcess::Execute( aiScene* pScene ) { aiMatrix4x4 scaling; aiMatrix4x4::Scaling( aiVector3D(scale), scaling ); - aiMatrix4x4 RotMatrix = aiMatrix4x4 (rotation.GetMatrix()); + const aiMatrix4x4 RotMatrix = aiMatrix4x4(rotation.GetMatrix()); bone->mOffsetMatrix = translation * RotMatrix * scaling; } diff --git a/code/PostProcessing/SortByPTypeProcess.cpp b/code/PostProcessing/SortByPTypeProcess.cpp index 1be75fc48..394ef15c8 100644 --- a/code/PostProcessing/SortByPTypeProcess.cpp +++ b/code/PostProcessing/SortByPTypeProcess.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -54,10 +52,7 @@ using namespace Assimp; // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -SortByPTypeProcess::SortByPTypeProcess() : - mConfigRemoveMeshes(0) { - // empty -} +SortByPTypeProcess::SortByPTypeProcess() : mConfigRemoveMeshes(0) {} // ------------------------------------------------------------------------------------------------ // Returns whether the processing step is present in the given flag field. @@ -155,7 +150,7 @@ void SortByPTypeProcess::Execute(aiScene *pScene) { if (1 == num) { if (!(mConfigRemoveMeshes & mesh->mPrimitiveTypes)) { *meshIdx = static_cast(outMeshes.size()); - outMeshes.push_back(mesh); + outMeshes.emplace_back(mesh); } else { delete mesh; pScene->mMeshes[i] = nullptr; @@ -311,21 +306,23 @@ void SortByPTypeProcess::Execute(aiScene *pScene) { if (vert) { *vert++ = mesh->mVertices[idx]; - //mesh->mVertices[idx].x = get_qnan(); } - if (nor) *nor++ = mesh->mNormals[idx]; + if (nor) + *nor++ = mesh->mNormals[idx]; if (tan) { *tan++ = mesh->mTangents[idx]; *bit++ = mesh->mBitangents[idx]; } for (unsigned int pp = 0; pp < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++pp) { - if (!uv[pp]) break; + if (!uv[pp]) + break; *uv[pp]++ = mesh->mTextureCoords[pp][idx]; } for (unsigned int pp = 0; pp < AI_MAX_NUMBER_OF_COLOR_SETS; ++pp) { - if (!cols[pp]) break; + if (!cols[pp]) + break; *cols[pp]++ = mesh->mColors[pp][idx]; } @@ -351,7 +348,7 @@ void SortByPTypeProcess::Execute(aiScene *pScene) { } } if (pp == mesh->mNumAnimMeshes) - amIdx++; + ++amIdx; in.mIndices[q] = outIdx++; } diff --git a/code/PostProcessing/SplitByBoneCountProcess.cpp b/code/PostProcessing/SplitByBoneCountProcess.cpp index 5324160d4..e44a55979 100644 --- a/code/PostProcessing/SplitByBoneCountProcess.cpp +++ b/code/PostProcessing/SplitByBoneCountProcess.cpp @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -166,7 +165,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector isBoneUsed( pMesh->mNumBones, false); // indices of the faces which are going to go into this submesh - std::vector subMeshFaces; + IndexArray subMeshFaces; subMeshFaces.reserve( pMesh->mNumFaces); // accumulated vertex count of all the faces in this submesh unsigned int numSubMeshVertices = 0; @@ -202,7 +201,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector::iterator it = newBonesAtCurrentFace.begin(); it != newBonesAtCurrentFace.end(); ++it) { if (!isBoneUsed[*it]) { isBoneUsed[*it] = true; - numBones++; + ++numBones; } } @@ -212,18 +211,17 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormName.length > 0 ) - { + if( pMesh->mName.length > 0 ) { newMesh->mName.Set( format() << pMesh->mName.data << "_sub" << poNewMeshes.size()); } newMesh->mMaterialIndex = pMesh->mMaterialIndex; newMesh->mPrimitiveTypes = pMesh->mPrimitiveTypes; - poNewMeshes.push_back( newMesh); + poNewMeshes.emplace_back( newMesh); // create all the arrays for this mesh if the old mesh contained them newMesh->mNumVertices = numSubMeshVertices; @@ -251,7 +249,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormFaces = new aiFace[subMeshFaces.size()]; unsigned int nvi = 0; // next vertex index - std::vector previousVertexIndices( numSubMeshVertices, std::numeric_limits::max()); // per new vertex: its index in the source mesh + IndexArray previousVertexIndices( numSubMeshVertices, std::numeric_limits::max()); // per new vertex: its index in the source mesh for( unsigned int a = 0; a < subMeshFaces.size(); ++a ) { const aiFace& srcFace = pMesh->mFaces[subMeshFaces[a]]; aiFace& dstFace = newMesh->mFaces[a]; @@ -399,10 +397,10 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormNumMeshes == 0 ) { - std::vector newMeshList; + IndexArray newMeshList; for( unsigned int a = 0; a < pNode->mNumMeshes; ++a) { unsigned int srcIndex = pNode->mMeshes[a]; - const std::vector& replaceMeshes = mSubMeshIndices[srcIndex]; + const IndexArray& replaceMeshes = mSubMeshIndices[srcIndex]; newMeshList.insert( newMeshList.end(), replaceMeshes.begin(), replaceMeshes.end()); } diff --git a/code/PostProcessing/SplitByBoneCountProcess.h b/code/PostProcessing/SplitByBoneCountProcess.h index 625019e0c..efe85824f 100644 --- a/code/PostProcessing/SplitByBoneCountProcess.h +++ b/code/PostProcessing/SplitByBoneCountProcess.h @@ -76,6 +76,10 @@ public: /// basing on the Importer's configuration property list. virtual void SetupProperties(const Importer* pImp) override; + /// @brief Will return the maximal number of bones. + /// @return The maximal number of bones. + size_t getMaxNumberOfBones() const; + protected: /// Executes the post processing step on the given imported data. /// At the moment a process is not supposed to fail. @@ -90,14 +94,19 @@ protected: /// Recursively updates the node's mesh list to account for the changed mesh list void UpdateNode( aiNode* pNode) const; -public: +private: /// Max bone count. Splitting occurs if a mesh has more than that number of bones. size_t mMaxBoneCount; /// Per mesh index: Array of indices of the new submeshes. - std::vector< std::vector > mSubMeshIndices; + using IndexArray = std::vector; + std::vector mSubMeshIndices; }; +inline size_t SplitByBoneCountProcess::getMaxNumberOfBones() const { + return mMaxBoneCount; +} + } // end of namespace Assimp #endif // !!AI_SPLITBYBONECOUNTPROCESS_H_INC diff --git a/include/assimp/Vertex.h b/include/assimp/Vertex.h index fd7eb037e..b4aa1dd2d 100644 --- a/include/assimp/Vertex.h +++ b/include/assimp/Vertex.h @@ -105,7 +105,7 @@ class Vertex { friend Vertex operator * (ai_real, const Vertex&); public: - Vertex() {} + Vertex() = default; // ---------------------------------------------------------------------------- /** Extract a particular vertex from a mesh and interleave all components */