From 5adb0e899c9defed135a439764a8e63e9868810f Mon Sep 17 00:00:00 2001 From: Chris Russ Date: Fri, 15 Jul 2016 13:20:16 +1000 Subject: [PATCH] CMake Option and moving more functions to optional double support --- CMakeLists.txt | 9 +++++++++ code/Assimp.cpp | 4 ++-- code/Exporter.cpp | 12 ++++++------ code/GenVertexNormalsProcess.cpp | 16 ++++++++-------- code/GenVertexNormalsProcess.h | 5 ++--- code/Importer.cpp | 10 +++++----- code/PlyExporter.cpp | 2 +- code/PretransformVertices.cpp | 3 +-- code/ProcessHelper.cpp | 8 ++++---- code/ProcessHelper.h | 8 ++++---- 10 files changed, 42 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b398e0ff..71e49693b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,15 @@ IF(NOT GIT_COMMIT_HASH) SET(GIT_COMMIT_HASH 0) ENDIF(NOT GIT_COMMIT_HASH) +OPTION(ASSIMP_DOUBLE_PRECISION + "Set to ON to enable double precision processing" + OFF +) + +IF(ASSIMP_DOUBLE_PRECISION) + ADD_DEFINITIONS(-DAI_DOUBLE_PRECISION) +ENDIF(ASSIMP_DOUBLE_PRECISION) + configure_file( ${CMAKE_CURRENT_LIST_DIR}/revision.h.in # ${CMAKE_CURRENT_SOURCE_DIR}/revision.h.in diff --git a/code/Assimp.cpp b/code/Assimp.cpp index 8507c8641..c28da95ee 100644 --- a/code/Assimp.cpp +++ b/code/Assimp.cpp @@ -546,11 +546,11 @@ ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szNam // ------------------------------------------------------------------------------------------------ // Importer::SetPropertyFloat -ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, float value) +ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, ai_real value) { ASSIMP_BEGIN_EXCEPTION_REGION(); PropertyMap* pp = reinterpret_cast(p); - SetGenericProperty(pp->floats,szName,value); + SetGenericProperty(pp->floats,szName,value); ASSIMP_END_EXCEPTION_REGION(void); } diff --git a/code/Exporter.cpp b/code/Exporter.cpp index af2267a62..0707a4f56 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -534,9 +534,9 @@ bool ExportProperties :: SetPropertyInteger(const char* szName, int iValue) // ------------------------------------------------------------------------------------------------ // Set a configuration property -bool ExportProperties :: SetPropertyFloat(const char* szName, float iValue) +bool ExportProperties :: SetPropertyFloat(const char* szName, ai_real iValue) { - return SetGenericProperty(mFloatProperties, szName,iValue); + return SetGenericProperty(mFloatProperties, szName,iValue); } // ------------------------------------------------------------------------------------------------ @@ -563,10 +563,10 @@ int ExportProperties :: GetPropertyInteger(const char* szName, // ------------------------------------------------------------------------------------------------ // Get a configuration property -float ExportProperties :: GetPropertyFloat(const char* szName, - float iErrorReturn /*= 10e10*/) const +ai_real ExportProperties :: GetPropertyFloat(const char* szName, + ai_real iErrorReturn /*= 10e10*/) const { - return GetGenericProperty(mFloatProperties,szName,iErrorReturn); + return GetGenericProperty(mFloatProperties,szName,iErrorReturn); } // ------------------------------------------------------------------------------------------------ @@ -603,7 +603,7 @@ bool ExportProperties :: HasPropertyBool(const char* szName) const // Has a configuration property bool ExportProperties :: HasPropertyFloat(const char* szName) const { - return HasGenericProperty(mFloatProperties, szName); + return HasGenericProperty(mFloatProperties, szName); }; // ------------------------------------------------------------------------------------------------ diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index 165c3f8fb..14b7962c0 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -78,8 +78,8 @@ bool GenVertexNormalsProcess::IsActive( unsigned int pFlags) const void GenVertexNormalsProcess::SetupProperties(const Importer* pImp) { // Get the current value of the AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE property - configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,175.f); - configMaxAngle = AI_DEG_TO_RAD(std::max(std::min(configMaxAngle,175.0f),0.0f)); + configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,(ai_real)175.0); + configMaxAngle = AI_DEG_TO_RAD(std::max(std::min(configMaxAngle,(ai_real)175.0),(ai_real)0.0)); } // ------------------------------------------------------------------------------------------------ @@ -123,7 +123,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int } // Allocate the array to hold the output normals - const float qnan = std::numeric_limits::quiet_NaN(); + const float qnan = std::numeric_limits::quiet_NaN(); pMesh->mNormals = new aiVector3D[pMesh->mNumVertices]; // Compute per-face normals but store them per-vertex @@ -154,13 +154,13 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int // check whether we can reuse the SpatialSort of a previous step. SpatialSort* vertexFinder = NULL; SpatialSort _vertexFinder; - float posEpsilon = 1e-5f; + ai_real posEpsilon = 1e-5; if (shared) { - std::vector >* avf; + std::vector >* avf; shared->GetProperty(AI_SPP_SPATIAL_SORT,avf); if (avf) { - std::pair& blubb = avf->operator [] (meshIndex); + std::pair& blubb = avf->operator [] (meshIndex); vertexFinder = &blubb.first; posEpsilon = blubb.second; } @@ -205,13 +205,13 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int // Slower code path if a smooth angle is set. There are many ways to achieve // the effect, this one is the most straightforward one. else { - const float fLimit = std::cos(configMaxAngle); + const ai_real fLimit = std::cos(configMaxAngle); for (unsigned int i = 0; i < pMesh->mNumVertices;++i) { // Get all vertices that share this one ... vertexFinder->FindPositions( pMesh->mVertices[i] , posEpsilon, verticesFound); aiVector3D vr = pMesh->mNormals[i]; - float vrlen = vr.Length(); + ai_real vrlen = vr.Length(); aiVector3D pcNor; for (unsigned int a = 0; a < verticesFound.size(); ++a) { diff --git a/code/GenVertexNormalsProcess.h b/code/GenVertexNormalsProcess.h index 5d8b61ead..caa327aa3 100644 --- a/code/GenVertexNormalsProcess.h +++ b/code/GenVertexNormalsProcess.h @@ -86,7 +86,7 @@ public: // setter for configMaxAngle - inline void SetMaxSmoothAngle(float f) + inline void SetMaxSmoothAngle(ai_real f) { configMaxAngle =f; } @@ -104,10 +104,9 @@ public: private: /** Configuration option: maximum smoothing angle, in radians*/ - float configMaxAngle; + ai_real configMaxAngle; }; } // end of namespace Assimp #endif // !!AI_GENVERTEXNORMALPROCESS_H_INC - diff --git a/code/Importer.cpp b/code/Importer.cpp index 3599138eb..978f7c7d4 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -1017,11 +1017,11 @@ bool Importer::SetPropertyInteger(const char* szName, int iValue) // ------------------------------------------------------------------------------------------------ // Set a configuration property -bool Importer::SetPropertyFloat(const char* szName, float iValue) +bool Importer::SetPropertyFloat(const char* szName, ai_real iValue) { bool exising; ASSIMP_BEGIN_EXCEPTION_REGION(); - exising = SetGenericProperty(pimpl->mFloatProperties, szName,iValue); + exising = SetGenericProperty(pimpl->mFloatProperties, szName,iValue); ASSIMP_END_EXCEPTION_REGION(bool); return exising; } @@ -1058,10 +1058,10 @@ int Importer::GetPropertyInteger(const char* szName, // ------------------------------------------------------------------------------------------------ // Get a configuration property -float Importer::GetPropertyFloat(const char* szName, - float iErrorReturn /*= 10e10*/) const +ai_real Importer::GetPropertyFloat(const char* szName, + ai_real iErrorReturn /*= 10e10*/) const { - return GetGenericProperty(pimpl->mFloatProperties,szName,iErrorReturn); + return GetGenericProperty(pimpl->mFloatProperties,szName,iErrorReturn); } // ------------------------------------------------------------------------------------------------ diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index e69c5e386..87f5bbee8 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -223,7 +223,7 @@ PlyExporter::~PlyExporter() { // ------------------------------------------------------------------------------------------------ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components) { - static const float inf = std::numeric_limits::infinity(); + static const ai_real inf = std::numeric_limits::infinity(); // If a component (for instance normal vectors) is present in at least one mesh in the scene, // then default values are written for meshes that do not contain this component. diff --git a/code/PretransformVertices.cpp b/code/PretransformVertices.cpp index 8158bdd6f..16a42e219 100644 --- a/code/PretransformVertices.cpp +++ b/code/PretransformVertices.cpp @@ -690,7 +690,7 @@ void PretransformVertices::Execute( aiScene* pScene) // find the dominant axis aiVector3D d = max-min; - const float div = std::max(d.x,std::max(d.y,d.z))*0.5f; + const ai_real div = std::max(d.x,std::max(d.y,d.z))*0.5; d = min+d*0.5f; for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) { @@ -721,4 +721,3 @@ void PretransformVertices::Execute( aiScene* pScene) DefaultLogger::get()->info(buffer); } } - diff --git a/code/ProcessHelper.cpp b/code/ProcessHelper.cpp index e18d54c30..e25c08c24 100644 --- a/code/ProcessHelper.cpp +++ b/code/ProcessHelper.cpp @@ -142,9 +142,9 @@ void FindMeshCenterTransformed (aiMesh* mesh, aiVector3D& out, } // ------------------------------------------------------------------------------- -float ComputePositionEpsilon(const aiMesh* pMesh) +ai_real ComputePositionEpsilon(const aiMesh* pMesh) { - const float epsilon = 1e-4f; + const ai_real epsilon = 1e-4; // calculate the position bounds so we have a reliable epsilon to check position differences against aiVector3D minVec, maxVec; @@ -153,11 +153,11 @@ float ComputePositionEpsilon(const aiMesh* pMesh) } // ------------------------------------------------------------------------------- -float ComputePositionEpsilon(const aiMesh* const* pMeshes, size_t num) +ai_real ComputePositionEpsilon(const aiMesh* const* pMeshes, size_t num) { ai_assert( NULL != pMeshes ); - const float epsilon = 1e-4f; + const ai_real epsilon = 1e-4; // calculate the position bounds so we have a reliable epsilon to check position differences against aiVector3D minVec, maxVec, mi, ma; diff --git a/code/ProcessHelper.h b/code/ProcessHelper.h index 3f50a46c6..c70e23f5f 100644 --- a/code/ProcessHelper.h +++ b/code/ProcessHelper.h @@ -231,7 +231,7 @@ inline void ArrayBounds(const T* in, unsigned int size, T& min, T& max) * @param pColor1 First color * @param pColor2 second color * @return Quadratic color difference */ -inline float GetColorDifference( const aiColor4D& pColor1, const aiColor4D& pColor2) +inline ai_real GetColorDifference( const aiColor4D& pColor1, const aiColor4D& pColor2) { const aiColor4D c (pColor1.r - pColor2.r, pColor1.g - pColor2.g, pColor1.b - pColor2.b, pColor1.a - pColor2.a); return c.r*c.r + c.g*c.g + c.b*c.b + c.a*c.a; @@ -293,12 +293,12 @@ void FindMeshCenterTransformed (aiMesh* mesh, aiVector3D& out,const aiMatrix4x4& // ------------------------------------------------------------------------------- // Compute a good epsilon value for position comparisons on a mesh -float ComputePositionEpsilon(const aiMesh* pMesh); +ai_real ComputePositionEpsilon(const aiMesh* pMesh); // ------------------------------------------------------------------------------- // Compute a good epsilon value for position comparisons on a array of meshes -float ComputePositionEpsilon(const aiMesh* const* pMeshes, size_t num); +ai_real ComputePositionEpsilon(const aiMesh* const* pMeshes, size_t num); // ------------------------------------------------------------------------------- @@ -345,7 +345,7 @@ class ComputeSpatialSortProcess : public BaseProcess void Execute( aiScene* pScene) { - typedef std::pair _Type; + typedef std::pair _Type; DefaultLogger::get()->debug("Generate spatially-sorted vertex cache"); std::vector<_Type>* p = new std::vector<_Type>(pScene->mNumMeshes);