From 2be6bac4b022232058008658726bb2a240f3fc8a Mon Sep 17 00:00:00 2001 From: kovacsv Date: Tue, 7 Dec 2021 20:42:43 +0100 Subject: [PATCH 1/9] Bug: Export crashes when any of the meshes contains texture coordinate names #4243 --- code/Common/SceneCombiner.cpp | 20 ++++++++++++++++++++ include/assimp/SceneCombiner.h | 1 + test/unit/Common/uiScene.cpp | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index 8f10d6308..7dbbf8860 100644 --- a/code/Common/SceneCombiner.cpp +++ b/code/Common/SceneCombiner.cpp @@ -1101,6 +1101,14 @@ void SceneCombiner::Copy(aiMesh **_dest, const aiMesh *src) { // make a deep copy of all blend shapes CopyPtrArray(dest->mAnimMeshes, dest->mAnimMeshes, dest->mNumAnimMeshes); + + // make a deep copy of all texture coordinate names + if (src->mTextureCoordsNames != nullptr) { + dest->mTextureCoordsNames = new aiString *[AI_MAX_NUMBER_OF_TEXTURECOORDS] {}; + for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { + Copy(&dest->mTextureCoordsNames[i], src->mTextureCoordsNames[i]); + } + } } // ------------------------------------------------------------------------------------------------ @@ -1348,6 +1356,18 @@ void SceneCombiner::Copy(aiMetadata **_dest, const aiMetadata *src) { } } +// ------------------------------------------------------------------------------------------------ +void SceneCombiner::Copy(aiString **_dest, const aiString *src) { + if (nullptr == _dest || nullptr == src) { + return; + } + + aiString *dest = *_dest = new aiString(); + + // get a flat copy + *dest = *src; +} + #if (__GNUC__ >= 8 && __GNUC_MINOR__ >= 0) #pragma GCC diagnostic pop #endif diff --git a/include/assimp/SceneCombiner.h b/include/assimp/SceneCombiner.h index 809ac30e4..874a885a5 100644 --- a/include/assimp/SceneCombiner.h +++ b/include/assimp/SceneCombiner.h @@ -361,6 +361,7 @@ public: static void Copy(aiNodeAnim **dest, const aiNodeAnim *src); static void Copy(aiMeshMorphAnim **dest, const aiMeshMorphAnim *src); static void Copy(aiMetadata **dest, const aiMetadata *src); + static void Copy(aiString **dest, const aiString *src); // recursive, of course static void Copy(aiNode **dest, const aiNode *src); diff --git a/test/unit/Common/uiScene.cpp b/test/unit/Common/uiScene.cpp index 1c531b042..af0b6ca01 100644 --- a/test/unit/Common/uiScene.cpp +++ b/test/unit/Common/uiScene.cpp @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "UnitTestPCH.h" #include +#include using namespace Assimp; @@ -88,5 +89,21 @@ TEST_F(utScene, getShortFilenameTest) { EXPECT_NE(nullptr, name2); } +TEST_F(utScene, deepCopyTest) { + scene->mRootNode = new aiNode(); + + scene->mNumMeshes = 1; + scene->mMeshes = new aiMesh *[scene->mNumMeshes] (); + scene->mMeshes[0] = new aiMesh (); + + scene->mMeshes[0]->SetTextureCoordsName (0, aiString ("test")); + + { + aiScene* copied = nullptr; + SceneCombiner::CopyScene(&copied,scene); + delete copied; + } +} + TEST_F(utScene, getEmbeddedTextureTest) { } From 1e4861f86ec3eef719f7aac22efbd7b37b696490 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 7 Dec 2021 20:45:21 +0100 Subject: [PATCH 2/9] Fix division by zero in PointInTriangle2D - closes https://github.com/assimp/assimp/issues/4240 --- code/Common/PolyTools.h | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/code/Common/PolyTools.h b/code/Common/PolyTools.h index e660ce49b..31100d060 100644 --- a/code/Common/PolyTools.h +++ b/code/Common/PolyTools.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -42,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file PolyTools.h, various utilities for our dealings with arbitrary polygons */ +#pragma once #ifndef AI_POLYTOOLS_H_INCLUDED #define AI_POLYTOOLS_H_INCLUDED @@ -55,8 +55,7 @@ namespace Assimp { * The function accepts an unconstrained template parameter for use with * both aiVector3D and aiVector2D, but generally ignores the third coordinate.*/ template -inline double GetArea2D(const T& v1, const T& v2, const T& v3) -{ +inline double GetArea2D(const T& v1, const T& v2, const T& v3) { return 0.5 * (v1.x * ((double)v3.y - v2.y) + v2.x * ((double)v1.y - v3.y) + v3.x * ((double)v2.y - v1.y)); } @@ -65,8 +64,7 @@ inline double GetArea2D(const T& v1, const T& v2, const T& v3) * The function accepts an unconstrained template parameter for use with * both aiVector3D and aiVector2D, but generally ignores the third coordinate.*/ template -inline bool OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) -{ +inline bool OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) { return GetArea2D(p0,p2,p1) > 0; } @@ -75,20 +73,23 @@ inline bool OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) * The function accepts an unconstrained template parameter for use with * both aiVector3D and aiVector2D, but generally ignores the third coordinate.*/ template -inline bool PointInTriangle2D(const T& p0, const T& p1,const T& p2, const T& pp) -{ +inline bool PointInTriangle2D(const T& p0, const T& p1,const T& p2, const T& pp) { // Point in triangle test using baryzentric coordinates const aiVector2D v0 = p1 - p0; const aiVector2D v1 = p2 - p0; const aiVector2D v2 = pp - p0; - double dot00 = v0 * v0; - double dot01 = v0 * v1; - double dot02 = v0 * v2; + const double dot00 = v0 * v0; + const double dot01 = v0 * v1; + const double dot02 = v0 * v2; double dot11 = v1 * v1; double dot12 = v1 * v2; - - const double invDenom = 1 / (dot00 * dot11 - dot01 * dot01); + const double denom = dot00 * dot11 - dot01 * dot01; + if (denom == 0.0) { + return false; + } + + const double invDenom = 1.0 / denom; dot11 = (dot11 * dot02 - dot01 * dot12) * invDenom; dot00 = (dot00 * dot12 - dot01 * dot02) * invDenom; @@ -133,8 +134,7 @@ inline bool IsCCW(T* in, size_t npoints) { // in[i+2].x, in[i+2].y)) { convex_turn = AI_MATH_PI_F - theta; convex_sum += convex_turn; - } - else { + } else { convex_sum -= AI_MATH_PI_F - theta; } } @@ -161,15 +161,13 @@ inline bool IsCCW(T* in, size_t npoints) { if (OnLeftSideOfLine2D(in[npoints-2],in[1],in[0])) { convex_turn = AI_MATH_PI_F - theta; convex_sum += convex_turn; - } - else { + } else { convex_sum -= AI_MATH_PI_F - theta; } return convex_sum >= (2 * AI_MATH_PI_F); } - // ------------------------------------------------------------------------------- /** Compute the normal of an arbitrary polygon in R3. * @@ -186,8 +184,7 @@ inline bool IsCCW(T* in, size_t npoints) { * this method is much faster than the 'other' NewellNormal() */ template -inline void NewellNormal (aiVector3t& out, int num, TReal* x, TReal* y, TReal* z) -{ +inline void NewellNormal (aiVector3t& out, int num, TReal* x, TReal* y, TReal* z) { // Duplicate the first two vertices at the end x[(num+0)*ofs_x] = x[0]; x[(num+1)*ofs_x] = x[ofs_x]; @@ -224,6 +221,6 @@ inline void NewellNormal (aiVector3t& out, int num, TReal* x, TReal* y, T out = aiVector3t(sum_yz,sum_zx,sum_xy); } -} // ! Assimp +} // ! namespace Assimp -#endif +#endif // AI_POLYTOOLS_H_INCLUDED From e51feac2c5b22db763123658f221a5fc74a105af Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 7 Dec 2021 21:19:01 +0100 Subject: [PATCH 3/9] Update PolyTools.h --- code/Common/PolyTools.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/Common/PolyTools.h b/code/Common/PolyTools.h index 31100d060..15276184e 100644 --- a/code/Common/PolyTools.h +++ b/code/Common/PolyTools.h @@ -79,11 +79,11 @@ inline bool PointInTriangle2D(const T& p0, const T& p1,const T& p2, const T& pp) const aiVector2D v1 = p2 - p0; const aiVector2D v2 = pp - p0; - const double dot00 = v0 * v0; + double dot00 = v0 * v0; + double dot11 = v1 * v1; const double dot01 = v0 * v1; const double dot02 = v0 * v2; - double dot11 = v1 * v1; - double dot12 = v1 * v2; + const double dot12 = v1 * v2; const double denom = dot00 * dot11 - dot01 * dot01; if (denom == 0.0) { return false; From c2297e91999794f44862101114c7b0de651eda01 Mon Sep 17 00:00:00 2001 From: Inho Lee Date: Wed, 8 Dec 2021 13:45:35 +0100 Subject: [PATCH 4/9] Revert "FBXConverter : Fix timescales of FBX animations" The previous patch was made by misunderstanding about mTime. It is not real time value, but time ticks. This reverts commit b8bf1eac041f0bbb406019a28f310509dad51b86. --- code/AssetLib/FBX/FBXConverter.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 098ba58e2..5a3ae0ae7 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -79,7 +79,7 @@ using namespace Util; #define MAGIC_NODE_TAG "_$AssimpFbx$" -#define CONVERT_FBX_TIME(time) (static_cast(time) * 1000.0 / 46186158000LL) +#define CONVERT_FBX_TIME(time) static_cast(time) / 46186158000LL FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBones) : defaultMaterialIndex(), @@ -2618,7 +2618,7 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) { meshMorphAnim->mKeys[j].mNumValuesAndWeights = numValuesAndWeights; meshMorphAnim->mKeys[j].mValues = new unsigned int[numValuesAndWeights]; meshMorphAnim->mKeys[j].mWeights = new double[numValuesAndWeights]; - meshMorphAnim->mKeys[j].mTime = CONVERT_FBX_TIME(animIt.first); + meshMorphAnim->mKeys[j].mTime = CONVERT_FBX_TIME(animIt.first) * anim_fps; for (unsigned int k = 0; k < numValuesAndWeights; k++) { meshMorphAnim->mKeys[j].mValues[k] = keyData->values.at(k); meshMorphAnim->mKeys[j].mWeights[k] = keyData->weights.at(k); @@ -2636,8 +2636,8 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) { return; } - double start_time_fps = has_local_startstop ? CONVERT_FBX_TIME(start_time) : min_time; - double stop_time_fps = has_local_startstop ? CONVERT_FBX_TIME(stop_time) : max_time; + double start_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(start_time) * anim_fps) : min_time; + double stop_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(stop_time) * anim_fps) : max_time; // adjust relative timing for animation for (unsigned int c = 0; c < anim->mNumChannels; c++) { @@ -3162,7 +3162,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, InterpolateKeys(outTranslations, keytimes, keyframeLists[TransformationComp_Translation], defTranslate, maxTime, minTime); } else { for (size_t i = 0; i < keyCount; ++i) { - outTranslations[i].mTime = CONVERT_FBX_TIME(keytimes[i]); + outTranslations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outTranslations[i].mValue = defTranslate; } } @@ -3171,7 +3171,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder); } else { for (size_t i = 0; i < keyCount; ++i) { - outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]); + outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outRotations[i].mValue = defQuat; } } @@ -3180,7 +3180,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name, InterpolateKeys(outScales, keytimes, keyframeLists[TransformationComp_Scaling], defScale, maxTime, minTime); } else { for (size_t i = 0; i < keyCount; ++i) { - outScales[i].mTime = CONVERT_FBX_TIME(keytimes[i]); + outScales[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outScales[i].mValue = defScale; } } @@ -3442,7 +3442,7 @@ void FBXConverter::InterpolateKeys(aiVectorKey *valOut, const KeyTimeList &keys, } // magic value to convert fbx times to seconds - valOut->mTime = CONVERT_FBX_TIME(time); + valOut->mTime = CONVERT_FBX_TIME(time) * anim_fps; min_time = std::min(min_time, valOut->mTime); max_time = std::max(max_time, valOut->mTime); From 68682d75b5323ebf45d662dd0d1de563442d147f Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 10 Dec 2021 08:39:21 +0100 Subject: [PATCH 5/9] Fix nullptr dereferencing from std::shared_ptr - Finding from fuzzer - closes https://github.com/assimp/assimp/issues/4237 --- code/AssetLib/DXF/DXFLoader.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/AssetLib/DXF/DXFLoader.cpp b/code/AssetLib/DXF/DXFLoader.cpp index 3b20678ad..2f1aa6961 100644 --- a/code/AssetLib/DXF/DXFLoader.cpp +++ b/code/AssetLib/DXF/DXFLoader.cpp @@ -378,6 +378,11 @@ void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& bloc const DXF::Block& bl_src = *(*it).second; for (std::shared_ptr pl_in : bl_src.lines) { + if (!pl_in) { + ASSIMP_LOG_ERROR("DXF: PolyLine instance is nullptr, skipping."); + continue; + } + std::shared_ptr pl_out = std::shared_ptr(new DXF::PolyLine(*pl_in)); if (bl_src.base.Length() || insert.scale.x!=1.f || insert.scale.y!=1.f || insert.scale.z!=1.f || insert.angle || insert.pos.Length()) { From 33c676227233c3b543df53284e905781dbf62c10 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 10 Dec 2021 14:32:45 +0100 Subject: [PATCH 6/9] Update HMPLoader.cpp - Fix possible division by zero - closes https://github.com/assimp/assimp/issues/4235 --- code/AssetLib/HMP/HMPLoader.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/code/AssetLib/HMP/HMPLoader.cpp b/code/AssetLib/HMP/HMPLoader.cpp index 661e4d1b2..0bc152680 100644 --- a/code/AssetLib/HMP/HMPLoader.cpp +++ b/code/AssetLib/HMP/HMPLoader.cpp @@ -473,16 +473,22 @@ void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char *szC // ------------------------------------------------------------------------------------------------ // Generate proepr texture coords -void HMPImporter::GenerateTextureCoords( - const unsigned int width, const unsigned int height) { +void HMPImporter::GenerateTextureCoords(const unsigned int width, const unsigned int height) { ai_assert(nullptr != pScene->mMeshes); ai_assert(nullptr != pScene->mMeshes[0]); ai_assert(nullptr != pScene->mMeshes[0]->mTextureCoords[0]); aiVector3D *uv = pScene->mMeshes[0]->mTextureCoords[0]; - - const float fY = (1.0f / height) + (1.0f / height) / (height - 1); - const float fX = (1.0f / width) + (1.0f / width) / (width - 1); + if (uv == nullptr) { + return; + } + + if (height == 0.0f || width == 0.0) { + return; + } + + const float fY = (1.0f / height) + (1.0f / height) / height; + const float fX = (1.0f / width) + (1.0f / width) / width; for (unsigned int y = 0; y < height; ++y) { for (unsigned int x = 0; x < width; ++x, ++uv) { From cb657e4c13f9ee9a8fd6eaf3f657c8a1abc8cb46 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 13 Dec 2021 18:06:23 +0100 Subject: [PATCH 7/9] Use correct XmlParser-methods and add some missing casts --- code/AssetLib/X3D/X3DImporter_Geometry3D.cpp | 2 +- code/AssetLib/glTF2/glTF2Exporter.cpp | 2 +- code/AssetLib/glTF2/glTF2Exporter.h | 3 +++ include/assimp/material.inl | 2 +- test/unit/utMaterialSystem.cpp | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/X3D/X3DImporter_Geometry3D.cpp b/code/AssetLib/X3D/X3DImporter_Geometry3D.cpp index 2db62dc64..b9fc2a4d8 100644 --- a/code/AssetLib/X3D/X3DImporter_Geometry3D.cpp +++ b/code/AssetLib/X3D/X3DImporter_Geometry3D.cpp @@ -879,7 +879,7 @@ void X3DImporter::readSphere(XmlNode &node) { X3DNodeElementBase *ne(nullptr); MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use); - XmlParser::getFloatAttribute(node, "radius", radius); + XmlParser::getRealAttribute(node, "radius", radius); XmlParser::getBoolAttribute(node, "solid", solid); // if "USE" defined then find already defined element. diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index e5c8b4530..606a4a919 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1410,7 +1410,7 @@ void glTF2Exporter::ExportMetadata() { } } -inline Ref GetSamplerInputRef(Asset &asset, std::string &animId, Ref &buffer, std::vector ×) { +inline Ref GetSamplerInputRef(Asset &asset, std::string &animId, Ref &buffer, std::vector ×) { return ExportData(asset, animId, buffer, (unsigned int)times.size(), ×[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT); } diff --git a/code/AssetLib/glTF2/glTF2Exporter.h b/code/AssetLib/glTF2/glTF2Exporter.h index 6d70d915e..d328f8a80 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.h +++ b/code/AssetLib/glTF2/glTF2Exporter.h @@ -66,7 +66,9 @@ class Ref; } namespace glTF2 { + class Asset; + struct TexProperty; struct TextureInfo; struct NormalTextureInfo; @@ -84,6 +86,7 @@ struct MaterialIOR; typedef float(vec2)[2]; typedef float(vec3)[3]; typedef float(vec4)[4]; + } // namespace glTF2 namespace Assimp { diff --git a/include/assimp/material.inl b/include/assimp/material.inl index 693785c3c..27f17ec28 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -105,7 +105,7 @@ aiReturn aiMaterial::Get(const char* pKey,unsigned int type, return AI_FAILURE; } - iNum = std::min((size_t)iNum,prop->mDataLength / sizeof(Type)); + iNum = (unsigned int)std::min((size_t)iNum,prop->mDataLength / sizeof(Type)); ::memcpy(pOut,prop->mData,iNum * sizeof(Type)); if (pMax) { *pMax = iNum; diff --git a/test/unit/utMaterialSystem.cpp b/test/unit/utMaterialSystem.cpp index 8db014d9c..6f1be1608 100644 --- a/test/unit/utMaterialSystem.cpp +++ b/test/unit/utMaterialSystem.cpp @@ -73,7 +73,7 @@ TEST_F(MaterialSystemTest, testFloatArrayProperty) { pf[0] = pf[1] = pf[2] = pf[3] = 12.0f; EXPECT_EQ(AI_SUCCESS, pcMat->Get("testKey2", 0, 0, pf, &pMax)); - EXPECT_EQ(sizeof(pf) / sizeof(float), pMax); + EXPECT_EQ(sizeof(pf) / sizeof(float), static_cast(pMax)); EXPECT_TRUE(!pf[0] && 1.0f == pf[1] && 2.0f == pf[2] && 3.0f == pf[3]); } From e4f38810cad912e2dea23e2810e6f77e00358fbf Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 13 Dec 2021 18:12:19 +0100 Subject: [PATCH 8/9] Add missing static casts --- include/assimp/material.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/material.inl b/include/assimp/material.inl index 27f17ec28..7f4b44575 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -105,7 +105,7 @@ aiReturn aiMaterial::Get(const char* pKey,unsigned int type, return AI_FAILURE; } - iNum = (unsigned int)std::min((size_t)iNum,prop->mDataLength / sizeof(Type)); + iNum = static_cast(std::min(static_cast(iNum),prop->mDataLength / sizeof(Type))); ::memcpy(pOut,prop->mData,iNum * sizeof(Type)); if (pMax) { *pMax = iNum; From 65bc801734702a977e66d9f2d16ca723f955051f Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 13 Dec 2021 18:48:58 +0100 Subject: [PATCH 9/9] Some fixes for possible divisions by zero --- include/assimp/SkeletonMeshBuilder.h | 3 +- include/assimp/color4.h | 2 - include/assimp/light.h | 1 - include/assimp/material.inl | 88 +++++++++----------------- include/assimp/texture.h | 19 +++--- include/assimp/vector2.h | 2 - include/assimp/vector3.inl | 92 ++++++++++------------------ 7 files changed, 70 insertions(+), 137 deletions(-) diff --git a/include/assimp/SkeletonMeshBuilder.h b/include/assimp/SkeletonMeshBuilder.h index 2479f4308..37d12f03d 100644 --- a/include/assimp/SkeletonMeshBuilder.h +++ b/include/assimp/SkeletonMeshBuilder.h @@ -6,7 +6,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -102,7 +101,7 @@ protected: /** Creates a dummy material and returns it. */ aiMaterial *CreateMaterial(); -protected: +private: /** space to assemble the mesh data: points */ std::vector mVertices; diff --git a/include/assimp/color4.h b/include/assimp/color4.h index fdd8f031e..573745ed6 100644 --- a/include/assimp/color4.h +++ b/include/assimp/color4.h @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/include/assimp/light.h b/include/assimp/light.h index f35f51e0a..46acad5fd 100644 --- a/include/assimp/light.h +++ b/include/assimp/light.h @@ -255,5 +255,4 @@ struct aiLight { } #endif - #endif // !! AI_LIGHT_H_INC diff --git a/include/assimp/material.inl b/include/assimp/material.inl index 7f4b44575..7a3cce741 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -44,21 +44,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once -#ifndef AI_MATERIAL_INL_INC -#define AI_MATERIAL_INL_INC #ifdef __GNUC__ # pragma GCC system_header #endif // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiPropertyTypeInfo ai_real_to_property_type_info(float) { +AI_FORCE_INLINE aiPropertyTypeInfo ai_real_to_property_type_info(float) { return aiPTI_Float; } -AI_FORCE_INLINE -aiPropertyTypeInfo ai_real_to_property_type_info(double) { +AI_FORCE_INLINE aiPropertyTypeInfo ai_real_to_property_type_info(double) { return aiPTI_Double; } // --------------------------------------------------------------------------- @@ -66,8 +62,7 @@ aiPropertyTypeInfo ai_real_to_property_type_info(double) { //! @cond never // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::GetTexture( aiTextureType type, +AI_FORCE_INLINE aiReturn aiMaterial::GetTexture( aiTextureType type, unsigned int index, C_STRUCT aiString* path, aiTextureMapping* mapping /*= NULL*/, @@ -79,15 +74,13 @@ aiReturn aiMaterial::GetTexture( aiTextureType type, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -unsigned int aiMaterial::GetTextureCount(aiTextureType type) const { +AI_FORCE_INLINE unsigned int aiMaterial::GetTextureCount(aiTextureType type) const { return ::aiGetMaterialTextureCount(this,type); } // --------------------------------------------------------------------------- template -AI_FORCE_INLINE -aiReturn aiMaterial::Get(const char* pKey,unsigned int type, +AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx, Type* pOut, unsigned int* pMax) const { unsigned int iNum = pMax ? *pMax : 1; @@ -116,8 +109,7 @@ aiReturn aiMaterial::Get(const char* pKey,unsigned int type, // --------------------------------------------------------------------------- template -AI_FORCE_INLINE -aiReturn aiMaterial::Get(const char* pKey,unsigned int type, +AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,Type& pOut) const { const aiMaterialProperty* prop; const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx, @@ -138,34 +130,29 @@ aiReturn aiMaterial::Get(const char* pKey,unsigned int type, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::Get(const char* pKey,unsigned int type, +AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,ai_real* pOut, unsigned int* pMax) const { return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax); } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::Get(const char* pKey,unsigned int type, +AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,int* pOut, unsigned int* pMax) const { return ::aiGetMaterialIntegerArray(this,pKey,type,idx,pOut,pMax); } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::Get(const char* pKey,unsigned int type, +AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,ai_real& pOut) const { return aiGetMaterialFloat(this,pKey,type,idx,&pOut); } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::Get(const char* pKey,unsigned int type, +AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,int& pOut) const { return aiGetMaterialInteger(this,pKey,type,idx,&pOut); } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::Get(const char* pKey,unsigned int type, +AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,aiColor4D& pOut) const { return aiGetMaterialColor(this,pKey,type,idx,&pOut); } @@ -190,14 +177,10 @@ AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, // --------------------------------------------------------------------------- template -aiReturn aiMaterial::AddProperty (const TYPE* pInput, - const unsigned int pNumValues, - const char* pKey, - unsigned int type, - unsigned int index) -{ - return AddBinaryProperty((const void*)pInput, - pNumValues * sizeof(TYPE), +aiReturn aiMaterial::AddProperty (const TYPE* pInput, + const unsigned int pNumValues, const char* pKey, unsigned int type, + unsigned int index) { + return AddBinaryProperty((const void*)pInput, pNumValues * sizeof(TYPE), pKey,type,index,aiPTI_Buffer); } @@ -213,8 +196,7 @@ AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const float* pInput, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const double* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const double* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -225,8 +207,7 @@ aiReturn aiMaterial::AddProperty(const double* pInput, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -237,8 +218,7 @@ aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiColor4D* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiColor4D* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -249,8 +229,7 @@ aiReturn aiMaterial::AddProperty(const aiColor4D* pInput, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiColor3D* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiColor3D* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -261,8 +240,7 @@ aiReturn aiMaterial::AddProperty(const aiColor3D* pInput, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiVector3D* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiVector3D* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -273,8 +251,7 @@ aiReturn aiMaterial::AddProperty(const aiVector3D* pInput, } // --------------------------------------------------------------------------- -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const int* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const int* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -293,8 +270,7 @@ aiReturn aiMaterial::AddProperty(const int* pInput, // --------------------------------------------------------------------------- template<> -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const float* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const float* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -306,8 +282,7 @@ aiReturn aiMaterial::AddProperty(const float* pInput, // --------------------------------------------------------------------------- template<> -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const double* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const double* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -319,8 +294,7 @@ aiReturn aiMaterial::AddProperty(const double* pInput, // --------------------------------------------------------------------------- template<> -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -332,8 +306,7 @@ aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput, // --------------------------------------------------------------------------- template<> -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiColor4D* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiColor4D* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -345,8 +318,7 @@ aiReturn aiMaterial::AddProperty(const aiColor4D* pInput, // --------------------------------------------------------------------------- template<> -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiColor3D* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiColor3D* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -358,8 +330,7 @@ aiReturn aiMaterial::AddProperty(const aiColor3D* pInput, // --------------------------------------------------------------------------- template<> -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const aiVector3D* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiVector3D* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -371,8 +342,7 @@ aiReturn aiMaterial::AddProperty(const aiVector3D* pInput, // --------------------------------------------------------------------------- template<> -AI_FORCE_INLINE -aiReturn aiMaterial::AddProperty(const int* pInput, +AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const int* pInput, const unsigned int pNumValues, const char* pKey, unsigned int type, @@ -383,5 +353,3 @@ aiReturn aiMaterial::AddProperty(const int* pInput, } //! @endcond - -#endif //! AI_MATERIAL_INL_INC diff --git a/include/assimp/texture.h b/include/assimp/texture.h index 7a9d38cc0..ec156114b 100644 --- a/include/assimp/texture.h +++ b/include/assimp/texture.h @@ -92,22 +92,19 @@ struct aiTexel { #ifdef __cplusplus //! Comparison operator - bool operator== (const aiTexel& other) const - { + bool operator== (const aiTexel& other) const { return b == other.b && r == other.r && g == other.g && a == other.a; } //! Inverse comparison operator - bool operator!= (const aiTexel& other) const - { + bool operator!= (const aiTexel& other) const { return b != other.b || r != other.r || g != other.g || a != other.a; } //! Conversion to a floating-point 4d color - operator aiColor4D() const - { + operator aiColor4D() const { return aiColor4D(r/255.f,g/255.f,b/255.f,a/255.f); } #endif // __cplusplus @@ -202,11 +199,11 @@ struct aiTexture { } // Construction - aiTexture() AI_NO_EXCEPT - : mWidth(0) - , mHeight(0) - , pcData(nullptr) - , mFilename() { + aiTexture() AI_NO_EXCEPT : + mWidth(0), + mHeight(0), + pcData(nullptr), + mFilename() { memset(achFormatHint, 0, sizeof(achFormatHint)); } diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index 34adf894b..586d63244 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, diff --git a/include/assimp/vector3.inl b/include/assimp/vector3.inl index 0076d2a85..80d2c55a1 100644 --- a/include/assimp/vector3.inl +++ b/include/assimp/vector3.inl @@ -54,8 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ------------------------------------------------------------------------------------------------ /** Transformation of a vector by a 3x3 matrix */ template -AI_FORCE_INLINE -aiVector3t operator * (const aiMatrix3x3t& pMatrix, const aiVector3t& pVector) { +AI_FORCE_INLINE aiVector3t operator * (const aiMatrix3x3t& pMatrix, const aiVector3t& pVector) { aiVector3t res; res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z; res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z; @@ -66,8 +65,7 @@ aiVector3t operator * (const aiMatrix3x3t& pMatrix, const aiVector // ------------------------------------------------------------------------------------------------ /** Transformation of a vector by a 4x4 matrix */ template -AI_FORCE_INLINE -aiVector3t operator * (const aiMatrix4x4t& pMatrix, const aiVector3t& pVector) { +AI_FORCE_INLINE aiVector3t operator * (const aiMatrix4x4t& pMatrix, const aiVector3t& pVector) { aiVector3t res; res.x = pMatrix.a1 * pVector.x + pMatrix.a2 * pVector.y + pMatrix.a3 * pVector.z + pMatrix.a4; res.y = pMatrix.b1 * pVector.x + pMatrix.b2 * pVector.y + pMatrix.b3 * pVector.z + pMatrix.b4; @@ -82,36 +80,35 @@ aiVector3t::operator aiVector3t () const { } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -void aiVector3t::Set( TReal pX, TReal pY, TReal pZ) { +AI_FORCE_INLINE void aiVector3t::Set( TReal pX, TReal pY, TReal pZ) { x = pX; y = pY; z = pZ; } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -TReal aiVector3t::SquareLength() const { +AI_FORCE_INLINE TReal aiVector3t::SquareLength() const { return x*x + y*y + z*z; } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -TReal aiVector3t::Length() const { +AI_FORCE_INLINE TReal aiVector3t::Length() const { return std::sqrt( SquareLength()); } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -aiVector3t& aiVector3t::Normalize() { + aiVector3t& aiVector3t::Normalize() { + const TReal l = Length(); + if (l == 0) { + return *this; + } *this /= Length(); return *this; } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -aiVector3t& aiVector3t::NormalizeSafe() { +AI_FORCE_INLINE aiVector3t& aiVector3t::NormalizeSafe() { TReal len = Length(); if ( len > static_cast< TReal >( 0 ) ) { *this /= len; @@ -120,8 +117,7 @@ aiVector3t& aiVector3t::NormalizeSafe() { } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -const aiVector3t& aiVector3t::operator += (const aiVector3t& o) { +AI_FORCE_INLINE const aiVector3t& aiVector3t::operator += (const aiVector3t& o) { x += o.x; y += o.y; z += o.z; @@ -130,8 +126,7 @@ const aiVector3t& aiVector3t::operator += (const aiVector3t } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -const aiVector3t& aiVector3t::operator -= (const aiVector3t& o) { +AI_FORCE_INLINE const aiVector3t& aiVector3t::operator -= (const aiVector3t& o) { x -= o.x; y -= o.y; z -= o.z; @@ -140,8 +135,7 @@ const aiVector3t& aiVector3t::operator -= (const aiVector3t } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -const aiVector3t& aiVector3t::operator *= (TReal f) { +AI_FORCE_INLINE const aiVector3t& aiVector3t::operator *= (TReal f) { x *= f; y *= f; z *= f; @@ -150,8 +144,7 @@ const aiVector3t& aiVector3t::operator *= (TReal f) { } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -const aiVector3t& aiVector3t::operator /= (TReal f) { +AI_FORCE_INLINE const aiVector3t& aiVector3t::operator /= (TReal f) { if ( f == static_cast(0.0)) { return *this; } @@ -164,20 +157,17 @@ const aiVector3t& aiVector3t::operator /= (TReal f) { } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -aiVector3t& aiVector3t::operator *= (const aiMatrix3x3t& mat){ +AI_FORCE_INLINE aiVector3t& aiVector3t::operator *= (const aiMatrix3x3t& mat){ return (*this = mat * (*this)); } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -aiVector3t& aiVector3t::operator *= (const aiMatrix4x4t& mat){ +AI_FORCE_INLINE aiVector3t& aiVector3t::operator *= (const aiMatrix4x4t& mat){ return (*this = mat * (*this)); } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -TReal aiVector3t::operator[](unsigned int i) const { +AI_FORCE_INLINE TReal aiVector3t::operator[](unsigned int i) const { switch (i) { case 0: return x; @@ -192,9 +182,7 @@ TReal aiVector3t::operator[](unsigned int i) const { } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -TReal& aiVector3t::operator[](unsigned int i) { -// return *(&x + i); +AI_FORCE_INLINE TReal& aiVector3t::operator[](unsigned int i) { switch (i) { case 0: return x; @@ -209,20 +197,17 @@ TReal& aiVector3t::operator[](unsigned int i) { } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -bool aiVector3t::operator== (const aiVector3t& other) const { +AI_FORCE_INLINE bool aiVector3t::operator== (const aiVector3t& other) const { return x == other.x && y == other.y && z == other.z; } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -bool aiVector3t::operator!= (const aiVector3t& other) const { +AI_FORCE_INLINE bool aiVector3t::operator!= (const aiVector3t& other) const { return x != other.x || y != other.y || z != other.z; } // --------------------------------------------------------------------------- template -AI_FORCE_INLINE -bool aiVector3t::Equal(const aiVector3t& other, TReal epsilon) const { +AI_FORCE_INLINE bool aiVector3t::Equal(const aiVector3t& other, TReal epsilon) const { return std::abs(x - other.x) <= epsilon && std::abs(y - other.y) <= epsilon && @@ -230,77 +215,66 @@ bool aiVector3t::Equal(const aiVector3t& other, TReal epsilon) con } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -bool aiVector3t::operator < (const aiVector3t& other) const { +AI_FORCE_INLINE bool aiVector3t::operator < (const aiVector3t& other) const { return x != other.x ? x < other.x : y != other.y ? y < other.y : z < other.z; } // ------------------------------------------------------------------------------------------------ template -AI_FORCE_INLINE -const aiVector3t aiVector3t::SymMul(const aiVector3t& o) { +AI_FORCE_INLINE const aiVector3t aiVector3t::SymMul(const aiVector3t& o) { return aiVector3t(x*o.x,y*o.y,z*o.z); } // ------------------------------------------------------------------------------------------------ // symmetric addition template -AI_FORCE_INLINE -aiVector3t operator + (const aiVector3t& v1, const aiVector3t& v2) { +AI_FORCE_INLINE aiVector3t operator + (const aiVector3t& v1, const aiVector3t& v2) { return aiVector3t( v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); } // ------------------------------------------------------------------------------------------------ // symmetric subtraction template -AI_FORCE_INLINE -aiVector3t operator - (const aiVector3t& v1, const aiVector3t& v2) { +AI_FORCE_INLINE aiVector3t operator - (const aiVector3t& v1, const aiVector3t& v2) { return aiVector3t( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); } // ------------------------------------------------------------------------------------------------ // scalar product template -AI_FORCE_INLINE -TReal operator * (const aiVector3t& v1, const aiVector3t& v2) { +AI_FORCE_INLINE TReal operator * (const aiVector3t& v1, const aiVector3t& v2) { return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; } // ------------------------------------------------------------------------------------------------ // scalar multiplication template -AI_FORCE_INLINE -aiVector3t operator * ( TReal f, const aiVector3t& v) { +AI_FORCE_INLINE aiVector3t operator * ( TReal f, const aiVector3t& v) { return aiVector3t( f*v.x, f*v.y, f*v.z); } // ------------------------------------------------------------------------------------------------ // and the other way around template -AI_FORCE_INLINE -aiVector3t operator * ( const aiVector3t& v, TReal f) { +AI_FORCE_INLINE aiVector3t operator * ( const aiVector3t& v, TReal f) { return aiVector3t( f*v.x, f*v.y, f*v.z); } // ------------------------------------------------------------------------------------------------ // scalar division template -AI_FORCE_INLINE -aiVector3t operator / ( const aiVector3t& v, TReal f) { +AI_FORCE_INLINE aiVector3t operator / ( const aiVector3t& v, TReal f) { return v * (1/f); } // ------------------------------------------------------------------------------------------------ // vector division template -AI_FORCE_INLINE -aiVector3t operator / ( const aiVector3t& v, const aiVector3t& v2) { +AI_FORCE_INLINE aiVector3t operator / ( const aiVector3t& v, const aiVector3t& v2) { return aiVector3t(v.x / v2.x,v.y / v2.y,v.z / v2.z); } // ------------------------------------------------------------------------------------------------ // cross product template -AI_FORCE_INLINE -aiVector3t operator ^ ( const aiVector3t& v1, const aiVector3t& v2) { +AI_FORCE_INLINE aiVector3t operator ^ ( const aiVector3t& v1, const aiVector3t& v2) { return aiVector3t( v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x); } // ------------------------------------------------------------------------------------------------ // vector negation template -AI_FORCE_INLINE -aiVector3t operator - ( const aiVector3t& v) { +AI_FORCE_INLINE aiVector3t operator - ( const aiVector3t& v) { return aiVector3t( -v.x, -v.y, -v.z); }