diff --git a/code/AssetLib/IFC/IFCUtil.cpp b/code/AssetLib/IFC/IFCUtil.cpp index 6cf104833..eb636d735 100644 --- a/code/AssetLib/IFC/IFCUtil.cpp +++ b/code/AssetLib/IFC/IFCUtil.cpp @@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "AssetLib/IFC/IFCUtil.h" #include "Common/PolyTools.h" +#include "Geometry/GeometryUtils.h" #include "PostProcessing/ProcessHelper.h" namespace Assimp { @@ -235,7 +236,7 @@ IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const { struct CompareVector { bool operator () (const IfcVector3& a, const IfcVector3& b) const { IfcVector3 d = a - b; - IfcFloat eps = ai_epsilon; + constexpr IfcFloat eps = ai_epsilon; return d.x < -eps || (std::abs(d.x) < eps && d.y < -eps) || (std::abs(d.x) < eps && std::abs(d.y) < eps && d.z < -eps); } }; diff --git a/code/AssetLib/LWO/LWOLoader.cpp b/code/AssetLib/LWO/LWOLoader.cpp index 1bf39b2da..dc7015d34 100644 --- a/code/AssetLib/LWO/LWOLoader.cpp +++ b/code/AssetLib/LWO/LWOLoader.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, @@ -51,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "AssetLib/LWO/LWOLoader.h" #include "PostProcessing/ConvertToLHProcess.h" #include "PostProcessing/ProcessHelper.h" +#include "Geometry/GeometryUtils.h" #include #include @@ -528,7 +527,6 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector & continue; vNormals += v; } - mesh->mNormals[idx] = vNormals.Normalize(); } } } @@ -549,7 +547,6 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector & const aiVector3D &v = faceNormals[*a]; vNormals += v; } - vNormals.Normalize(); for (std::vector::const_iterator a = poResult.begin(); a != poResult.end(); ++a) { mesh->mNormals[*a] = vNormals; vertexDone[*a] = true; @@ -557,6 +554,7 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector & } } } + GeometryUtils::normalizeVectorArray(mesh->mNormals, mesh->mNormals, mesh->mNumVertices); } // ------------------------------------------------------------------------------------------------ diff --git a/code/Geometry/GeometryUtils.cpp b/code/Geometry/GeometryUtils.cpp index ad99f2224..cec1e74c5 100644 --- a/code/Geometry/GeometryUtils.cpp +++ b/code/Geometry/GeometryUtils.cpp @@ -45,32 +45,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { +// ------------------------------------------------------------------------------------------------ ai_real GeometryUtils::heron( ai_real a, ai_real b, ai_real c ) { - ai_real s = (a + b + c) / 2; - ai_real area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), (ai_real)0.5 ); + const ai_real s = (a + b + c) / 2; + const ai_real area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), (ai_real)0.5 ); return area; } -ai_real GeometryUtils::distance3D( const aiVector3D &vA, aiVector3D &vB ) { +// ------------------------------------------------------------------------------------------------ +ai_real GeometryUtils::distance3D( const aiVector3D &vA, const aiVector3D &vB ) { const ai_real lx = ( vB.x - vA.x ); const ai_real ly = ( vB.y - vA.y ); const ai_real lz = ( vB.z - vA.z ); - ai_real a = lx*lx + ly*ly + lz*lz; - ai_real d = pow( a, (ai_real)0.5 ); + const ai_real a = lx*lx + ly*ly + lz*lz; + const ai_real d = pow( a, (ai_real)0.5 ); return d; } +// ------------------------------------------------------------------------------------------------ ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh ) { ai_real area = 0; - aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] ); - aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] ); - aiVector3D vC( mesh->mVertices[ face.mIndices[ 2 ] ] ); + const aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] ); + const aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] ); + const aiVector3D vC( mesh->mVertices[ face.mIndices[ 2 ] ] ); - ai_real a( distance3D( vA, vB ) ); - ai_real b( distance3D( vB, vC ) ); - ai_real c( distance3D( vC, vA ) ); + const ai_real a = distance3D( vA, vB ); + const ai_real b = distance3D( vB, vC ); + const ai_real c = distance3D( vC, vA ); area = heron( a, b, c ); return area; diff --git a/code/Geometry/GeometryUtils.h b/code/Geometry/GeometryUtils.h index b3d1c05f8..b6fff99e1 100644 --- a/code/Geometry/GeometryUtils.h +++ b/code/Geometry/GeometryUtils.h @@ -55,7 +55,7 @@ public: /// @param vA Vector a. /// @param vB Vector b. /// @return The distance. - static ai_real distance3D( const aiVector3D &vA, aiVector3D &vB ); + static ai_real distance3D( const aiVector3D &vA, const aiVector3D &vB ); /// @brief Will calculate the area of a triangle described by a aiFace. /// @param face The face diff --git a/code/PostProcessing/ArmaturePopulate.cpp b/code/PostProcessing/ArmaturePopulate.cpp index a29735205..12244bc78 100644 --- a/code/PostProcessing/ArmaturePopulate.cpp +++ b/code/PostProcessing/ArmaturePopulate.cpp @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include +//#include namespace Assimp { @@ -74,7 +74,7 @@ void ArmaturePopulate::Execute(aiScene *out) { BuildBoneList(out->mRootNode, out->mRootNode, out, bones); BuildNodeList(out->mRootNode, nodes); - BuildBoneStack(out->mRootNode, out->mRootNode, out, bones, bone_stack, nodes); + BuildBoneStack(out->mRootNode, out, bones, bone_stack, nodes); ASSIMP_LOG_DEBUG("Bone stack size: ", bone_stack.size()); @@ -162,8 +162,7 @@ void ArmaturePopulate::BuildNodeList(const aiNode *current_node, // A bone stack allows us to have multiple armatures, with the same bone names // A bone stack allows us also to retrieve bones true transform even with // duplicate names :) -void ArmaturePopulate::BuildBoneStack(aiNode *, - const aiNode *root_node, +void ArmaturePopulate::BuildBoneStack(const aiNode *root_node, const aiScene*, const std::vector &bones, std::map &bone_stack, @@ -199,8 +198,7 @@ void ArmaturePopulate::BuildBoneStack(aiNode *, // This is required to be detected for a bone initially, it will recurse up // until it cannot find another bone and return the node No known failure // points. (yet) -aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node, - std::vector &bone_list) { +aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node, std::vector &bone_list) { while (nullptr != bone_node) { if (!IsBoneNode(bone_node->mName, bone_list)) { ASSIMP_LOG_VERBOSE_DEBUG("GetArmatureRoot() Found valid armature: ", bone_node->mName.C_Str()); diff --git a/code/PostProcessing/ArmaturePopulate.h b/code/PostProcessing/ArmaturePopulate.h index 83cbf8cf7..52d3adfef 100644 --- a/code/PostProcessing/ArmaturePopulate.h +++ b/code/PostProcessing/ArmaturePopulate.h @@ -96,7 +96,7 @@ public: const aiScene *scene, std::vector &bones); - static void BuildBoneStack(aiNode *current_node, const aiNode *root_node, + static void BuildBoneStack(const aiNode *root_node, const aiScene *scene, const std::vector &bones, std::map &bone_stack, diff --git a/include/assimp/defs.h b/include/assimp/defs.h index ddb209bec..e3743f419 100644 --- a/include/assimp/defs.h +++ b/include/assimp/defs.h @@ -283,7 +283,11 @@ typedef unsigned int ai_uint; #define AI_RAD_TO_DEG(x) ((x) * (ai_real) 57.2957795) /* Numerical limits */ -static const ai_real ai_epsilon = (ai_real) 1e-6; +#ifdef __cplusplus +constexpr ai_real ai_epsilon = (ai_real) 1e-6; +#else +const ai_real ai_epsilon = (ai_real) 1e-6; +#endif /* Support for big-endian builds */ #if defined(__BYTE_ORDER__)