diff --git a/code/AssetLib/3DS/3DSHelper.h b/code/AssetLib/3DS/3DSHelper.h index 8f85f2e4d..271a2cc7b 100644 --- a/code/AssetLib/3DS/3DSHelper.h +++ b/code/AssetLib/3DS/3DSHelper.h @@ -365,14 +365,13 @@ struct Texture { #ifdef _MSC_VER #pragma warning(pop) #endif // _MSC_VER - // --------------------------------------------------------------------------- /** Helper structure representing a 3ds material */ struct Material { //! Default constructor has been deleted Material() : mName(), - mDiffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)), + mDiffuse(0.6f, 0.6f, 0.6f), mSpecularExponent(ai_real(0.0)), mShininessStrength(ai_real(1.0)), mShading(Discreet3DS::Gouraud), @@ -385,7 +384,7 @@ struct Material { //! Constructor with explicit name explicit Material(const std::string &name) : mName(name), - mDiffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)), + mDiffuse(0.6f, 0.6f, 0.6f), mSpecularExponent(ai_real(0.0)), mShininessStrength(ai_real(1.0)), mShading(Discreet3DS::Gouraud), diff --git a/code/AssetLib/ASE/ASEParser.cpp b/code/AssetLib/ASE/ASEParser.cpp index c071ae900..067cce1a5 100644 --- a/code/AssetLib/ASE/ASEParser.cpp +++ b/code/AssetLib/ASE/ASEParser.cpp @@ -421,7 +421,7 @@ void Parser::ParseLV1SoftSkinBlock() { me.first = static_cast(curMesh->mBones.size()); curMesh->mBones.emplace_back(bone); } - ParseLV4MeshFloat(me.second); + ParseLV4MeshReal(me.second); // Add the new bone weight to list vert.mBoneWeights.push_back(me); @@ -579,14 +579,14 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) { } // material transparency if (TokenMatch(filePtr, "MATERIAL_TRANSPARENCY", 21)) { - ParseLV4MeshFloat(mat.mTransparency); + ParseLV4MeshReal(mat.mTransparency); mat.mTransparency = ai_real(1.0) - mat.mTransparency; continue; } // material self illumination if (TokenMatch(filePtr, "MATERIAL_SELFILLUM", 18)) { ai_real f = 0.0; - ParseLV4MeshFloat(f); + ParseLV4MeshReal(f); mat.mEmissive.r = f; mat.mEmissive.g = f; @@ -595,7 +595,7 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) { } // material shininess if (TokenMatch(filePtr, "MATERIAL_SHINE", 14)) { - ParseLV4MeshFloat(mat.mSpecularExponent); + ParseLV4MeshReal(mat.mSpecularExponent); mat.mSpecularExponent *= 15; continue; } @@ -606,7 +606,7 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) { } // material shininess strength if (TokenMatch(filePtr, "MATERIAL_SHINESTRENGTH", 22)) { - ParseLV4MeshFloat(mat.mShininessStrength); + ParseLV4MeshReal(mat.mShininessStrength); continue; } // diffuse color map @@ -730,32 +730,32 @@ void Parser::ParseLV3MapBlock(Texture &map) { } // offset on the u axis if (TokenMatch(filePtr, "UVW_U_OFFSET", 12)) { - ParseLV4MeshFloat(map.mOffsetU); + ParseLV4MeshReal(map.mOffsetU); continue; } // offset on the v axis if (TokenMatch(filePtr, "UVW_V_OFFSET", 12)) { - ParseLV4MeshFloat(map.mOffsetV); + ParseLV4MeshReal(map.mOffsetV); continue; } // tiling on the u axis if (TokenMatch(filePtr, "UVW_U_TILING", 12)) { - ParseLV4MeshFloat(map.mScaleU); + ParseLV4MeshReal(map.mScaleU); continue; } // tiling on the v axis if (TokenMatch(filePtr, "UVW_V_TILING", 12)) { - ParseLV4MeshFloat(map.mScaleV); + ParseLV4MeshReal(map.mScaleV); continue; } // rotation around the z-axis if (TokenMatch(filePtr, "UVW_ANGLE", 9)) { - ParseLV4MeshFloat(map.mRotation); + ParseLV4MeshReal(map.mRotation); continue; } // map blending factor if (TokenMatch(filePtr, "MAP_AMOUNT", 10)) { - ParseLV4MeshFloat(map.mTextureBlend); + ParseLV4MeshReal(map.mTextureBlend); continue; } } @@ -894,15 +894,15 @@ void Parser::ParseLV2CameraSettingsBlock(ASE::Camera &camera) { if ('*' == *filePtr) { ++filePtr; if (TokenMatch(filePtr, "CAMERA_NEAR", 11)) { - ParseLV4MeshFloat(camera.mNear); + ParseLV4MeshReal(camera.mNear); continue; } if (TokenMatch(filePtr, "CAMERA_FAR", 10)) { - ParseLV4MeshFloat(camera.mFar); + ParseLV4MeshReal(camera.mFar); continue; } if (TokenMatch(filePtr, "CAMERA_FOV", 10)) { - ParseLV4MeshFloat(camera.mFOV); + ParseLV4MeshReal(camera.mFOV); continue; } } @@ -921,15 +921,15 @@ void Parser::ParseLV2LightSettingsBlock(ASE::Light &light) { continue; } if (TokenMatch(filePtr, "LIGHT_INTENS", 12)) { - ParseLV4MeshFloat(light.mIntensity); + ParseLV4MeshReal(light.mIntensity); continue; } if (TokenMatch(filePtr, "LIGHT_HOTSPOT", 13)) { - ParseLV4MeshFloat(light.mAngle); + ParseLV4MeshReal(light.mAngle); continue; } if (TokenMatch(filePtr, "LIGHT_FALLOFF", 13)) { - ParseLV4MeshFloat(light.mFalloff); + ParseLV4MeshReal(light.mFalloff); continue; } } @@ -1037,7 +1037,7 @@ void Parser::ParseLV3ScaleAnimationBlock(ASE::Animation &anim) { if (b) { anim.akeyScaling.emplace_back(); aiVectorKey &key = anim.akeyScaling.back(); - ParseLV4MeshFloatTriple(&key.mValue.x, iIndex); + ParseLV4MeshRealTriple(&key.mValue.x, iIndex); key.mTime = (double)iIndex; } } @@ -1076,7 +1076,7 @@ void Parser::ParseLV3PosAnimationBlock(ASE::Animation &anim) { if (b) { anim.akeyPositions.emplace_back(); aiVectorKey &key = anim.akeyPositions.back(); - ParseLV4MeshFloatTriple(&key.mValue.x, iIndex); + ParseLV4MeshRealTriple(&key.mValue.x, iIndex); key.mTime = (double)iIndex; } } @@ -1117,8 +1117,8 @@ void Parser::ParseLV3RotAnimationBlock(ASE::Animation &anim) { aiQuatKey &key = anim.akeyRotations.back(); aiVector3D v; ai_real f; - ParseLV4MeshFloatTriple(&v.x, iIndex); - ParseLV4MeshFloat(f); + ParseLV4MeshRealTriple(&v.x, iIndex); + ParseLV4MeshReal(f); key.mTime = (double)iIndex; key.mValue = aiQuaternion(v, f); } @@ -1162,23 +1162,23 @@ void Parser::ParseLV2NodeTransformBlock(ASE::BaseNode &mesh) { // fourth row of the transformation matrix - and also the // only information here that is interesting for targets if (TokenMatch(filePtr, "TM_ROW3", 7)) { - ParseLV4MeshFloatTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x)); + ParseLV4MeshRealTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x)); continue; } if (mode == 1) { // first row of the transformation matrix if (TokenMatch(filePtr, "TM_ROW0", 7)) { - ParseLV4MeshFloatTriple(mesh.mTransform[0]); + ParseLV4MeshRealTriple(mesh.mTransform[0]); continue; } // second row of the transformation matrix if (TokenMatch(filePtr, "TM_ROW1", 7)) { - ParseLV4MeshFloatTriple(mesh.mTransform[1]); + ParseLV4MeshRealTriple(mesh.mTransform[1]); continue; } // third row of the transformation matrix if (TokenMatch(filePtr, "TM_ROW2", 7)) { - ParseLV4MeshFloatTriple(mesh.mTransform[2]); + ParseLV4MeshRealTriple(mesh.mTransform[2]); continue; } // inherited position axes @@ -1413,7 +1413,7 @@ void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mes // --- ignored ai_real afVert[3]; - ParseLV4MeshFloatTriple(afVert); + ParseLV4MeshRealTriple(afVert); std::pair pairOut; while (true) { @@ -1452,7 +1452,7 @@ void Parser::ParseLV3MeshVertexListBlock( aiVector3D vTemp; unsigned int iIndex; - ParseLV4MeshFloatTriple(&vTemp.x, iIndex); + ParseLV4MeshRealTriple(&vTemp.x, iIndex); if (iIndex >= iNumVertices) { LogWarning("Invalid vertex index. It will be ignored"); @@ -1505,7 +1505,7 @@ void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices, if (TokenMatch(filePtr, "MESH_TVERT", 10)) { aiVector3D vTemp; unsigned int iIndex; - ParseLV4MeshFloatTriple(&vTemp.x, iIndex); + ParseLV4MeshRealTriple(&vTemp.x, iIndex); if (iIndex >= iNumVertices) { LogWarning("Tvertex has an invalid index. It will be ignored"); @@ -1599,7 +1599,7 @@ void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh &mesh) aiColor4D vTemp; vTemp.a = 1.0f; unsigned int iIndex; - ParseLV4MeshFloatTriple(&vTemp.r, iIndex); + ParseLV4MeshRealTriple(&vTemp.r, iIndex); if (iIndex >= iNumVertices) { LogWarning("Vertex color has an invalid index. It will be ignored"); @@ -1656,7 +1656,7 @@ void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) { ++filePtr; if (faceIdx != UINT_MAX && TokenMatch(filePtr, "MESH_VERTEXNORMAL", 17)) { aiVector3D vNormal; - ParseLV4MeshFloatTriple(&vNormal.x, index); + ParseLV4MeshRealTriple(&vNormal.x, index); if (faceIdx >= sMesh.mFaces.size()) continue; @@ -1678,7 +1678,7 @@ void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) { } if (TokenMatch(filePtr, "MESH_FACENORMAL", 15)) { aiVector3D vNormal; - ParseLV4MeshFloatTriple(&vNormal.x, faceIdx); + ParseLV4MeshRealTriple(&vNormal.x, faceIdx); if (faceIdx >= sMesh.mFaces.size()) { ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_FACENORMAL section"); @@ -1843,7 +1843,17 @@ void Parser::ParseLV4MeshLongTriple(unsigned int *apOut, unsigned int &rIndexOut ParseLV4MeshLongTriple(apOut); } // ------------------------------------------------------------------------------------------------ -void Parser::ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut) { +void Parser::ParseLV4MeshRealTriple(ai_real *apOut, unsigned int &rIndexOut) { + ai_assert(nullptr != apOut); + + // parse the index + ParseLV4MeshLong(rIndexOut); + + // parse the three others + ParseLV4MeshRealTriple(apOut); +} +// ------------------------------------------------------------------------------------------------ +void Parser::ParseLV4MeshFloatTriple(float* apOut, unsigned int& rIndexOut) { ai_assert(nullptr != apOut); // parse the index @@ -1853,7 +1863,15 @@ void Parser::ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut) { ParseLV4MeshFloatTriple(apOut); } // ------------------------------------------------------------------------------------------------ -void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) { +void Parser::ParseLV4MeshRealTriple(ai_real *apOut) { + ai_assert(nullptr != apOut); + + for (unsigned int i = 0; i < 3; ++i) { + ParseLV4MeshReal(apOut[i]); + } +} +// ------------------------------------------------------------------------------------------------ +void Parser::ParseLV4MeshFloatTriple(float* apOut) { ai_assert(nullptr != apOut); for (unsigned int i = 0; i < 3; ++i) { @@ -1861,7 +1879,7 @@ void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) { } } // ------------------------------------------------------------------------------------------------ -void Parser::ParseLV4MeshFloat(ai_real &fOut) { +void Parser::ParseLV4MeshReal(ai_real &fOut) { // skip spaces and tabs if (!SkipSpaces(&filePtr, mEnd)) { // LOG @@ -1874,6 +1892,19 @@ void Parser::ParseLV4MeshFloat(ai_real &fOut) { filePtr = fast_atoreal_move(filePtr, fOut); } // ------------------------------------------------------------------------------------------------ +void Parser::ParseLV4MeshFloat(float &fOut) { + // skip spaces and tabs + if (!SkipSpaces(&filePtr, mEnd)) { + // LOG + LogWarning("Unable to parse float: unexpected EOL [#1]"); + fOut = 0.0; + ++iLineNumber; + return; + } + // parse the first float + filePtr = fast_atoreal_move(filePtr, fOut); +} +// ------------------------------------------------------------------------------------------------ void Parser::ParseLV4MeshLong(unsigned int &iOut) { // Skip spaces and tabs if (!SkipSpaces(&filePtr, mEnd)) { diff --git a/code/AssetLib/ASE/ASEParser.h b/code/AssetLib/ASE/ASEParser.h index 263b5ca73..eb6be64ae 100644 --- a/code/AssetLib/ASE/ASEParser.h +++ b/code/AssetLib/ASE/ASEParser.h @@ -553,13 +553,15 @@ private: //! (also works for MESH_TVERT, MESH_CFACE, MESH_VERTCOL ...) //! \param apOut Output buffer (3 floats) //! \param rIndexOut Output index - void ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut); + void ParseLV4MeshRealTriple(ai_real *apOut, unsigned int &rIndexOut); + void ParseLV4MeshFloatTriple(float *apOut, unsigned int &rIndexOut); // ------------------------------------------------------------------- //! Parse a *MESH_VERT block in a file //! (also works for MESH_TVERT, MESH_CFACE, MESH_VERTCOL ...) //! \param apOut Output buffer (3 floats) - void ParseLV4MeshFloatTriple(ai_real *apOut); + void ParseLV4MeshRealTriple(ai_real *apOut); + void ParseLV4MeshFloatTriple(float *apOut); // ------------------------------------------------------------------- //! Parse a *MESH_TFACE block in a file @@ -577,7 +579,8 @@ private: // ------------------------------------------------------------------- //! Parse a single float element //! \param fOut Output float - void ParseLV4MeshFloat(ai_real &fOut); + void ParseLV4MeshReal(ai_real &fOut); + void ParseLV4MeshFloat(float &fOut); // ------------------------------------------------------------------- //! Parse a single int element diff --git a/code/AssetLib/MDL/MDLMaterialLoader.cpp b/code/AssetLib/MDL/MDLMaterialLoader.cpp index f68f8e23e..7adb76d94 100644 --- a/code/AssetLib/MDL/MDLMaterialLoader.cpp +++ b/code/AssetLib/MDL/MDLMaterialLoader.cpp @@ -610,7 +610,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7( if (is_not_qnan(clrTexture.r)) { clrTemp.r *= clrTexture.a; } - pcMatOut->AddProperty(&clrTemp.r, 1, AI_MATKEY_OPACITY); + pcMatOut->AddProperty(&clrTemp.r, 1, AI_MATKEY_OPACITY); // read phong power int iShadingMode = (int)aiShadingMode_Gouraud; diff --git a/code/AssetLib/Obj/ObjFileData.h b/code/AssetLib/Obj/ObjFileData.h index 3dc20c799..205c855e5 100644 --- a/code/AssetLib/Obj/ObjFileData.h +++ b/code/AssetLib/Obj/ObjFileData.h @@ -199,12 +199,12 @@ struct Material { //! Constructor Material() : - diffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)), + diffuse(0.6f, 0.6f, 0.6f), alpha(ai_real(1.0)), shineness(ai_real(0.0)), illumination_model(1), ior(ai_real(1.0)), - transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)), + transparent(1.0f, 1.0, 1.0), roughness(), metallic(), sheen(), diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index bd1d6aedd..9abac7ee2 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -743,14 +743,14 @@ ASSIMP_API void aiVector2DivideByVector( } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiVector2Length( +ASSIMP_API ai_real aiVector2Length( const C_STRUCT aiVector2D *v) { ai_assert(nullptr != v); return v->Length(); } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiVector2SquareLength( +ASSIMP_API ai_real aiVector2SquareLength( const C_STRUCT aiVector2D *v) { ai_assert(nullptr != v); return v->SquareLength(); @@ -764,7 +764,7 @@ ASSIMP_API void aiVector2Negate( } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiVector2DotProduct( +ASSIMP_API ai_real aiVector2DotProduct( const C_STRUCT aiVector2D *a, const C_STRUCT aiVector2D *b) { ai_assert(nullptr != a); @@ -859,14 +859,14 @@ ASSIMP_API void aiVector3DivideByVector( } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiVector3Length( +ASSIMP_API ai_real aiVector3Length( const C_STRUCT aiVector3D *v) { ai_assert(nullptr != v); return v->Length(); } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiVector3SquareLength( +ASSIMP_API ai_real aiVector3SquareLength( const C_STRUCT aiVector3D *v) { ai_assert(nullptr != v); return v->SquareLength(); @@ -880,7 +880,7 @@ ASSIMP_API void aiVector3Negate( } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiVector3DotProduct( +ASSIMP_API ai_real aiVector3DotProduct( const C_STRUCT aiVector3D *a, const C_STRUCT aiVector3D *b) { ai_assert(nullptr != a); @@ -966,7 +966,7 @@ ASSIMP_API void aiMatrix3Inverse(C_STRUCT aiMatrix3x3 *mat) { } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiMatrix3Determinant(const C_STRUCT aiMatrix3x3 *mat) { +ASSIMP_API ai_real aiMatrix3Determinant(const C_STRUCT aiMatrix3x3 *mat) { ai_assert(nullptr != mat); return mat->Determinant(); } @@ -1066,7 +1066,7 @@ ASSIMP_API void aiMatrix4Inverse(C_STRUCT aiMatrix4x4 *mat) { } // ------------------------------------------------------------------------------------------------ -ASSIMP_API float aiMatrix4Determinant(const C_STRUCT aiMatrix4x4 *mat) { +ASSIMP_API ai_real aiMatrix4Determinant(const C_STRUCT aiMatrix4x4 *mat) { ai_assert(nullptr != mat); return mat->Determinant(); } diff --git a/code/Material/MaterialSystem.cpp b/code/Material/MaterialSystem.cpp index 7e2fb51b9..f6328b119 100644 --- a/code/Material/MaterialSystem.cpp +++ b/code/Material/MaterialSystem.cpp @@ -174,6 +174,96 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial *pMat, return AI_SUCCESS; } +// ------------------------------------------------------------------------------------------------ +// Get an array of floating-point values from the material. +aiReturn aiGetMaterialDoubleArray(const aiMaterial *pMat, + const char *pKey, + unsigned int type, + unsigned int index, + double *pOut, + unsigned int *pMax) { + ai_assert(pOut != nullptr); + ai_assert(pMat != nullptr); + + const aiMaterialProperty *prop; + aiGetMaterialProperty(pMat, pKey, type, index, (const aiMaterialProperty **)&prop); + if (nullptr == prop) { + return AI_FAILURE; + } + + // data is given in floats, convert to ai_real + unsigned int iWrite = 0; + if (aiPTI_Float == prop->mType || aiPTI_Buffer == prop->mType) { + iWrite = prop->mDataLength / sizeof(float); + if (pMax) { + iWrite = std::min(*pMax, iWrite); + ; + } + + for (unsigned int a = 0; a < iWrite; ++a) { + pOut[a] = static_cast(reinterpret_cast(prop->mData)[a]); + } + + if (pMax) { + *pMax = iWrite; + } + } + // data is given in doubles, convert to float + else if (aiPTI_Double == prop->mType) { + iWrite = prop->mDataLength / sizeof(double); + if (pMax) { + iWrite = std::min(*pMax, iWrite); + ; + } + for (unsigned int a = 0; a < iWrite; ++a) { + pOut[a] = static_cast(reinterpret_cast(prop->mData)[a]); + } + if (pMax) { + *pMax = iWrite; + } + } + // data is given in ints, convert to float + else if (aiPTI_Integer == prop->mType) { + iWrite = prop->mDataLength / sizeof(int32_t); + if (pMax) { + iWrite = std::min(*pMax, iWrite); + ; + } + for (unsigned int a = 0; a < iWrite; ++a) { + pOut[a] = static_cast(reinterpret_cast(prop->mData)[a]); + } + if (pMax) { + *pMax = iWrite; + } + } + // a string ... read floats separated by spaces + else { + if (pMax) { + iWrite = *pMax; + } + // strings are zero-terminated with a 32 bit length prefix, so this is safe + const char *cur = prop->mData + 4; + ai_assert(prop->mDataLength >= 5); + ai_assert(!prop->mData[prop->mDataLength - 1]); + for (unsigned int a = 0;; ++a) { + cur = fast_atoreal_move(cur, pOut[a]); + if (a == iWrite - 1) { + break; + } + if (!IsSpace(*cur)) { + ASSIMP_LOG_ERROR("Material property", pKey, + " is a string; failed to parse a float array out of it."); + return AI_FAILURE; + } + } + + if (pMax) { + *pMax = iWrite; + } + } + return AI_SUCCESS; +} + // ------------------------------------------------------------------------------------------------ // Get an array if integers from the material aiReturn aiGetMaterialIntegerArray(const aiMaterial *pMat, diff --git a/include/assimp/cimport.h b/include/assimp/cimport.h index b0b4e038a..80edfe221 100644 --- a/include/assimp/cimport.h +++ b/include/assimp/cimport.h @@ -644,14 +644,14 @@ ASSIMP_API void aiVector2DivideByVector( /** Get the length of a 2D vector. * @return v Vector to evaluate */ -ASSIMP_API float aiVector2Length( +ASSIMP_API ai_real aiVector2Length( const C_STRUCT aiVector2D *v); // -------------------------------------------------------------------------------- /** Get the squared length of a 2D vector. * @return v Vector to evaluate */ -ASSIMP_API float aiVector2SquareLength( +ASSIMP_API ai_real aiVector2SquareLength( const C_STRUCT aiVector2D *v); // -------------------------------------------------------------------------------- @@ -667,7 +667,7 @@ ASSIMP_API void aiVector2Negate( * @param b Second vector * @return The dot product of vectors */ -ASSIMP_API float aiVector2DotProduct( +ASSIMP_API ai_real aiVector2DotProduct( const C_STRUCT aiVector2D *a, const C_STRUCT aiVector2D *b); @@ -774,14 +774,14 @@ ASSIMP_API void aiVector3DivideByVector( /** Get the length of a 3D vector. * @return v Vector to evaluate */ -ASSIMP_API float aiVector3Length( +ASSIMP_API ai_real aiVector3Length( const C_STRUCT aiVector3D *v); // -------------------------------------------------------------------------------- /** Get the squared length of a 3D vector. * @return v Vector to evaluate */ -ASSIMP_API float aiVector3SquareLength( +ASSIMP_API ai_real aiVector3SquareLength( const C_STRUCT aiVector3D *v); // -------------------------------------------------------------------------------- @@ -797,7 +797,7 @@ ASSIMP_API void aiVector3Negate( * @param b Second vector * @return The dot product of vectors */ -ASSIMP_API float aiVector3DotProduct( +ASSIMP_API ai_real aiVector3DotProduct( const C_STRUCT aiVector3D *a, const C_STRUCT aiVector3D *b); @@ -889,7 +889,7 @@ ASSIMP_API void aiMatrix3Inverse( /** Get the determinant of a 3x3 matrix. * @param mat Matrix to get the determinant from */ -ASSIMP_API float aiMatrix3Determinant( +ASSIMP_API ai_real aiMatrix3Determinant( const C_STRUCT aiMatrix3x3 *mat); // -------------------------------------------------------------------------------- @@ -999,7 +999,7 @@ ASSIMP_API void aiMatrix4Inverse( * @param mat Matrix to get the determinant from * @return The determinant of the matrix */ -ASSIMP_API float aiMatrix4Determinant( +ASSIMP_API ai_real aiMatrix4Determinant( const C_STRUCT aiMatrix4x4 *mat); // -------------------------------------------------------------------------------- diff --git a/include/assimp/types.h b/include/assimp/types.h index 84981d483..4b52b4ad5 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -165,9 +165,9 @@ struct aiRay { struct aiColor3D { #ifdef __cplusplus aiColor3D() AI_NO_EXCEPT : r(0.0f), g(0.0f), b(0.0f) {} - aiColor3D(ai_real _r, ai_real _g, ai_real _b) : + aiColor3D(float _r, float _g, float _b) : r(_r), g(_g), b(_b) {} - explicit aiColor3D(ai_real _r) : + explicit aiColor3D(float _r) : r(_r), g(_r), b(_r) {} aiColor3D(const aiColor3D &o) : r(o.r), g(o.g), b(o.b) {} @@ -214,12 +214,12 @@ struct aiColor3D { } /** Access a specific color component */ - ai_real operator[](unsigned int i) const { + float operator[](unsigned int i) const { return *(&r + i); } /** Access a specific color component */ - ai_real &operator[](unsigned int i) { + float &operator[](unsigned int i) { if (0 == i) { return r; } else if (1 == i) { @@ -232,14 +232,14 @@ struct aiColor3D { /** Check whether a color is black */ bool IsBlack() const { - static const ai_real epsilon = ai_real(10e-3); + static const float epsilon = float(10e-3); return std::fabs(r) < epsilon && std::fabs(g) < epsilon && std::fabs(b) < epsilon; } #endif // !__cplusplus //! Red, green and blue color values - ai_real r, g, b; + float r, g, b; }; // !struct aiColor3D // ---------------------------------------------------------------------------------- diff --git a/test/unit/AssimpAPITest_aiMatrix3x3.cpp b/test/unit/AssimpAPITest_aiMatrix3x3.cpp index 7b4532dce..3a12b1e55 100644 --- a/test/unit/AssimpAPITest_aiMatrix3x3.cpp +++ b/test/unit/AssimpAPITest_aiMatrix3x3.cpp @@ -47,7 +47,7 @@ using namespace Assimp; class AssimpAPITest_aiMatrix3x3 : public AssimpMathTest { protected: - virtual void SetUp() { + void SetUp() override { result_c = result_cpp = aiMatrix3x3(); } @@ -114,10 +114,19 @@ TEST_F(AssimpAPITest_aiMatrix3x3, aiMatrix3InverseTest) { EXPECT_EQ(result_cpp, result_c); } +inline void AI_EXPECT_REAL_EQ(ai_real val1, ai_real val2) { +#ifdef ASSIMP_DOUBLE_PRECISION + EXPECT_DOUBLE_EQ((val1), (val2)); +#else + EXPECT_FLOAT_EQ((val1), (val2)); +#endif +} + TEST_F(AssimpAPITest_aiMatrix3x3, aiMatrix3DeterminantTest) { result_c = result_cpp = random_mat3(); - EXPECT_EQ(result_cpp.Determinant(), - aiMatrix3Determinant(&result_c)); + const ai_real det_1 = result_cpp.Determinant(); + const ai_real det_2 = aiMatrix3Determinant(&result_c); + AI_EXPECT_REAL_EQ(det_1, det_2); } TEST_F(AssimpAPITest_aiMatrix3x3, aiMatrix3RotationZTest) { diff --git a/test/unit/AssimpAPITest_aiMatrix4x4.cpp b/test/unit/AssimpAPITest_aiMatrix4x4.cpp index 2f17ea2ad..d57026348 100644 --- a/test/unit/AssimpAPITest_aiMatrix4x4.cpp +++ b/test/unit/AssimpAPITest_aiMatrix4x4.cpp @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "UnitTestPCH.h" #include "MathTest.h" +#include using namespace Assimp; @@ -63,8 +64,9 @@ protected: }; TEST_F(AssimpAPITest_aiMatrix4x4, isIdendityTest) { - aiMatrix4x4 m = aiMatrix4x4(1.001f, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - EXPECT_TRUE(m.IsIdentity(1e-3f)); + aiMatrix4x4 m = aiMatrix4x4(1 + Math::getEpsilon(), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + const bool result = m.IsIdentity(Math::getEpsilon()); + EXPECT_TRUE(result); } TEST_F(AssimpAPITest_aiMatrix4x4, aiIdentityMatrix4Test) { diff --git a/test/unit/utIssues.cpp b/test/unit/utIssues.cpp index 4a3fa1585..2611ffdb9 100644 --- a/test/unit/utIssues.cpp +++ b/test/unit/utIssues.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2024, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -51,21 +49,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -class utIssues : public ::testing::Test { - // empty -}; +class utIssues : public ::testing::Test {}; #ifndef ASSIMP_BUILD_NO_EXPORT TEST_F( utIssues, OpacityBugWhenExporting_727 ) { float opacity; - aiScene *scene( TestModelFacttory::createDefaultTestModel( opacity ) ); + aiScene *scene = TestModelFacttory::createDefaultTestModel(opacity); Assimp::Importer importer; Assimp::Exporter exporter; - std::string path = "dae"; const aiExportFormatDesc *desc = exporter.GetExportFormatDescription( 0 ); - EXPECT_NE( desc, nullptr ); + ASSERT_NE( desc, nullptr ); + + std::string path = "dae"; path.append("."); path.append( desc->fileExtension ); EXPECT_EQ( AI_SUCCESS, exporter.Export( scene, desc->id, path ) ); @@ -73,7 +70,6 @@ TEST_F( utIssues, OpacityBugWhenExporting_727 ) { ASSERT_NE( nullptr, newScene ); float newOpacity; if ( newScene->mNumMaterials > 0 ) { - std::cout << "Desc = " << desc->description << "\n"; EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) ); EXPECT_FLOAT_EQ( opacity, newOpacity ); }