From fb5b01958a448e1c3dea9b6b2796b8bf9f98a5a7 Mon Sep 17 00:00:00 2001 From: Paul Arden Date: Tue, 25 Feb 2020 11:03:07 +1100 Subject: [PATCH 01/10] Fix to read orthographic camera data. Manual merge for this branch. Fixes #3028 --- code/glTF2/glTF2Asset.inl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glTF2/glTF2Asset.inl b/code/glTF2/glTF2Asset.inl index 4259022e9..184ad7419 100644 --- a/code/glTF2/glTF2Asset.inl +++ b/code/glTF2/glTF2Asset.inl @@ -1087,10 +1087,10 @@ inline void Camera::Read(Value& obj, Asset& /*r*/) cameraProperties.perspective.znear = MemberOrDefault(*it, "znear", 0.01f); } else { - cameraProperties.ortographic.xmag = MemberOrDefault(obj, "xmag", 1.f); - cameraProperties.ortographic.ymag = MemberOrDefault(obj, "ymag", 1.f); - cameraProperties.ortographic.zfar = MemberOrDefault(obj, "zfar", 100.f); - cameraProperties.ortographic.znear = MemberOrDefault(obj, "znear", 0.01f); + cameraProperties.ortographic.xmag = MemberOrDefault(*it, "xmag", 1.f); + cameraProperties.ortographic.ymag = MemberOrDefault(*it, "ymag", 1.f); + cameraProperties.ortographic.zfar = MemberOrDefault(*it, "zfar", 100.f); + cameraProperties.ortographic.znear = MemberOrDefault(*it, "znear", 0.01f); } } From ae50c4ebdf23c7f6f61300dede5bf32e0d306eb2 Mon Sep 17 00:00:00 2001 From: Paul Arden Date: Tue, 25 Feb 2020 14:45:00 +1100 Subject: [PATCH 02/10] Add support for orthographic camera information and use in glTF2 importer. Fixes #3030. --- code/glTF2/glTF2Importer.cpp | 1 + include/assimp/camera.h | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index dd80aeba9..cd67e69b7 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -715,6 +715,7 @@ void glTF2Importer::ImportCameras(glTF2::Asset &r) { aicam->mClipPlaneFar = cam.cameraProperties.ortographic.zfar; aicam->mClipPlaneNear = cam.cameraProperties.ortographic.znear; aicam->mHorizontalFOV = 0.0; + aicam->mOrthographicWidth = cam.cameraProperties.ortographic.xmag; aicam->mAspect = 1.0f; if (0.f != cam.cameraProperties.ortographic.ymag) { aicam->mAspect = cam.cameraProperties.ortographic.xmag / cam.cameraProperties.ortographic.ymag; diff --git a/include/assimp/camera.h b/include/assimp/camera.h index adb749ff5..ef52fce71 100644 --- a/include/assimp/camera.h +++ b/include/assimp/camera.h @@ -171,15 +171,26 @@ struct aiCamera */ float mAspect; + /** Half horizontal orthographic width, in scene units. + * + * The orthographic width specifies the half width of the + * orthographic view box. If non-zero the camera is + * orthographic and the mAspect should define to the + * ratio between the orthographic width and height + * and mHorizontalFOV should be set to 0. + * The default value is 0 (not orthographic). + */ + float mOrthographicWidth; #ifdef __cplusplus aiCamera() AI_NO_EXCEPT - : mUp (0.f,1.f,0.f) - , mLookAt (0.f,0.f,1.f) - , mHorizontalFOV (0.25f * (float)AI_MATH_PI) - , mClipPlaneNear (0.1f) - , mClipPlaneFar (1000.f) - , mAspect (0.f) + : mUp (0.f,1.f,0.f) + , mLookAt (0.f,0.f,1.f) + , mHorizontalFOV (0.25f * (float)AI_MATH_PI) + , mClipPlaneNear (0.1f) + , mClipPlaneFar (1000.f) + , mAspect (0.f) + , mOrthographicWidth (0.f) {} /** @brief Get a *right-handed* camera matrix from me From e56def7585804f39ee4889d11afe2508207308d9 Mon Sep 17 00:00:00 2001 From: Paul Arden Date: Tue, 25 Feb 2020 14:52:59 +1100 Subject: [PATCH 03/10] Fix indentation. --- include/assimp/camera.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/assimp/camera.h b/include/assimp/camera.h index ef52fce71..e266119fe 100644 --- a/include/assimp/camera.h +++ b/include/assimp/camera.h @@ -180,7 +180,7 @@ struct aiCamera * and mHorizontalFOV should be set to 0. * The default value is 0 (not orthographic). */ - float mOrthographicWidth; + float mOrthographicWidth; #ifdef __cplusplus aiCamera() AI_NO_EXCEPT @@ -190,7 +190,7 @@ struct aiCamera , mClipPlaneNear (0.1f) , mClipPlaneFar (1000.f) , mAspect (0.f) - , mOrthographicWidth (0.f) + , mOrthographicWidth (0.f) {} /** @brief Get a *right-handed* camera matrix from me From d5d30c898bdabbebe73bbeddb2e1a93871a78603 Mon Sep 17 00:00:00 2001 From: napina Date: Sun, 22 Mar 2020 12:47:42 +0200 Subject: [PATCH 04/10] Optimized LimitBoneWeightsProcess. Added SmallVector to reduce heap allocations. Simplified algorithm and removed unnecessary copying. --- code/CMakeLists.txt | 1 + .../LimitBoneWeightsProcess.cpp | 135 ++++++++-------- include/assimp/SmallVector.h | 148 ++++++++++++++++++ 3 files changed, 212 insertions(+), 72 deletions(-) create mode 100644 include/assimp/SmallVector.h diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 0dff5d9e4..c0e4487af 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -121,6 +121,7 @@ SET( PUBLIC_HEADERS ${HEADER_PATH}/GenericProperty.h ${HEADER_PATH}/SpatialSort.h ${HEADER_PATH}/SkeletonMeshBuilder.h + ${HEADER_PATH}/SmallVector.h ${HEADER_PATH}/SmoothingGroups.h ${HEADER_PATH}/SmoothingGroups.inl ${HEADER_PATH}/StandardShapes.h diff --git a/code/PostProcessing/LimitBoneWeightsProcess.cpp b/code/PostProcessing/LimitBoneWeightsProcess.cpp index 1f1abfabb..dc4d658ec 100644 --- a/code/PostProcessing/LimitBoneWeightsProcess.cpp +++ b/code/PostProcessing/LimitBoneWeightsProcess.cpp @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "LimitBoneWeightsProcess.h" +#include #include #include #include @@ -52,7 +53,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; - // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer LimitBoneWeightsProcess::LimitBoneWeightsProcess() @@ -76,10 +76,12 @@ bool LimitBoneWeightsProcess::IsActive( unsigned int pFlags) const // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. -void LimitBoneWeightsProcess::Execute( aiScene* pScene) { +void LimitBoneWeightsProcess::Execute( aiScene* pScene) +{ ASSIMP_LOG_DEBUG("LimitBoneWeightsProcess begin"); - for (unsigned int a = 0; a < pScene->mNumMeshes; ++a ) { - ProcessMesh(pScene->mMeshes[a]); + + for (unsigned int m = 0; m < pScene->mNumMeshes; ++m) { + ProcessMesh(pScene->mMeshes[m]); } ASSIMP_LOG_DEBUG("LimitBoneWeightsProcess end"); @@ -95,107 +97,96 @@ void LimitBoneWeightsProcess::SetupProperties(const Importer* pImp) // ------------------------------------------------------------------------------------------------ // Unites identical vertices in the given mesh -void LimitBoneWeightsProcess::ProcessMesh( aiMesh* pMesh) +void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh) { - if( !pMesh->HasBones()) + if (!pMesh->HasBones()) return; // collect all bone weights per vertex - typedef std::vector< std::vector< Weight > > WeightsPerVertex; - WeightsPerVertex vertexWeights( pMesh->mNumVertices); + typedef SmallVector VertexWeightArray; + typedef std::vector WeightsPerVertex; + WeightsPerVertex vertexWeights(pMesh->mNumVertices); + unsigned int maxVertexWeights = 0; - // collect all weights per vertex - for( unsigned int a = 0; a < pMesh->mNumBones; a++) + for (unsigned int b = 0; b < pMesh->mNumBones; ++b) { - const aiBone* bone = pMesh->mBones[a]; - for( unsigned int b = 0; b < bone->mNumWeights; b++) + const aiBone* bone = pMesh->mBones[b]; + for (unsigned int w = 0; w < bone->mNumWeights; ++w) { - const aiVertexWeight& w = bone->mWeights[b]; - vertexWeights[w.mVertexId].push_back( Weight( a, w.mWeight)); + const aiVertexWeight& vw = bone->mWeights[w]; + vertexWeights[vw.mVertexId].push_back(Weight(b, vw.mWeight)); + maxVertexWeights = std::max(maxVertexWeights, vertexWeights[vw.mVertexId].size()); } } + if (maxVertexWeights <= mMaxWeights) + return; + unsigned int removed = 0, old_bones = pMesh->mNumBones; // now cut the weight count if it exceeds the maximum - bool bChanged = false; - for( WeightsPerVertex::iterator vit = vertexWeights.begin(); vit != vertexWeights.end(); ++vit) + for (WeightsPerVertex::iterator vit = vertexWeights.begin(); vit != vertexWeights.end(); ++vit) { - if( vit->size() <= mMaxWeights) + if (vit->size() <= mMaxWeights) continue; - bChanged = true; - // more than the defined maximum -> first sort by weight in descending order. That's // why we defined the < operator in such a weird way. - std::sort( vit->begin(), vit->end()); + std::sort(vit->begin(), vit->end()); // now kill everything beyond the maximum count unsigned int m = static_cast(vit->size()); - vit->erase( vit->begin() + mMaxWeights, vit->end()); - removed += static_cast(m-vit->size()); + vit->resize(mMaxWeights); + removed += static_cast(m - vit->size()); // and renormalize the weights float sum = 0.0f; - for( std::vector::const_iterator it = vit->begin(); it != vit->end(); ++it ) { + for(const Weight* it = vit->begin(); it != vit->end(); ++it) { sum += it->mWeight; } - if( 0.0f != sum ) { + if (0.0f != sum) { const float invSum = 1.0f / sum; - for( std::vector::iterator it = vit->begin(); it != vit->end(); ++it ) { + for(Weight* it = vit->begin(); it != vit->end(); ++it) { it->mWeight *= invSum; } } } - if (bChanged) { - // rebuild the vertex weight array for all bones - typedef std::vector< std::vector< aiVertexWeight > > WeightsPerBone; - WeightsPerBone boneWeights( pMesh->mNumBones); - for( unsigned int a = 0; a < vertexWeights.size(); a++) + // clear weight count for all bone + for (unsigned int a = 0; a < pMesh->mNumBones; ++a) + { + pMesh->mBones[a]->mNumWeights = 0; + } + + // rebuild the vertex weight array for all bones + for (unsigned int a = 0; a < vertexWeights.size(); ++a) + { + const VertexWeightArray& vw = vertexWeights[a]; + for (const Weight* it = vw.begin(); it != vw.end(); ++it) { - const std::vector& vw = vertexWeights[a]; - for( std::vector::const_iterator it = vw.begin(); it != vw.end(); ++it) - boneWeights[it->mBone].push_back( aiVertexWeight( a, it->mWeight)); - } - - // and finally copy the vertex weight list over to the mesh's bones - std::vector abNoNeed(pMesh->mNumBones,false); - bChanged = false; - - for( unsigned int a = 0; a < pMesh->mNumBones; a++) - { - const std::vector& bw = boneWeights[a]; - aiBone* bone = pMesh->mBones[a]; - - if ( bw.empty() ) - { - abNoNeed[a] = bChanged = true; - continue; - } - - // copy the weight list. should always be less weights than before, so we don't need a new allocation - ai_assert( bw.size() <= bone->mNumWeights); - bone->mNumWeights = static_cast( bw.size() ); - ::memcpy( bone->mWeights, &bw[0], bw.size() * sizeof( aiVertexWeight)); - } - - if (bChanged) { - // the number of new bones is smaller than before, so we can reuse the old array - aiBone** ppcCur = pMesh->mBones;aiBone** ppcSrc = ppcCur; - - for (std::vector::const_iterator iter = abNoNeed.begin();iter != abNoNeed.end() ;++iter) { - if (*iter) { - delete *ppcSrc; - --pMesh->mNumBones; - } - else *ppcCur++ = *ppcSrc; - ++ppcSrc; - } - } - - if (!DefaultLogger::isNullLogger()) { - ASSIMP_LOG_INFO_F("Removed ", removed, " weights. Input bones: ", old_bones, ". Output bones: ", pMesh->mNumBones ); + aiBone* bone = pMesh->mBones[it->mBone]; + bone->mWeights[bone->mNumWeights++] = aiVertexWeight(a, it->mWeight); } } + + // remove empty bones + unsigned int writeBone = 0; + + for (unsigned int readBone = 0; readBone< pMesh->mNumBones; ++readBone) + { + aiBone* bone = pMesh->mBones[readBone]; + if (bone->mNumWeights > 0) + { + pMesh->mBones[writeBone++] = bone; + } + else + { + delete bone; + } + } + pMesh->mNumBones = writeBone; + + if (!DefaultLogger::isNullLogger()) { + ASSIMP_LOG_INFO_F("Removed ", removed, " weights. Input bones: ", old_bones, ". Output bones: ", pMesh->mNumBones); + } } diff --git a/include/assimp/SmallVector.h b/include/assimp/SmallVector.h new file mode 100644 index 000000000..ada241dda --- /dev/null +++ b/include/assimp/SmallVector.h @@ -0,0 +1,148 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2020, assimp team + + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file Defines small vector with inplace storage. +Based on CppCon 2016: Chandler Carruth "High Performance Code 201: Hybrid Data Structures" */ + +#pragma once +#ifndef AI_SMALLVECTOR_H_INC +#define AI_SMALLVECTOR_H_INC + +#ifdef __GNUC__ +# pragma GCC system_header +#endif + +namespace Assimp { + +// -------------------------------------------------------------------------------------------- +/** \brief Small vector with inplace storage. Reduces heap allocations when list is shorter +than initial capasity + */ +template +class SmallVector +{ +public: + SmallVector() + : mStorage(mInplaceStorage) + , mSize(0) + , mCapasity(Capasity) + { + } + + ~SmallVector() + { + if (mStorage != mInplaceStorage) { + delete [] mStorage; + } + } + + void push_back(const T& item) + { + if (mSize < mCapasity) { + mStorage[mSize++] = item; + } + else push_back_and_grow(item); + } + + void resize(unsigned int newSize) + { + if (newSize > mCapasity) + grow(newSize); + mSize = newSize; + } + + unsigned int size() const + { + return mSize; + } + + T* begin() + { + return mStorage; + } + + T* end() + { + return &mStorage[mSize]; + } + + T* begin() const + { + return mStorage; + } + + T* end() const + { + return &mStorage[mSize]; + } + +private: + void grow(unsigned int newCapasity) + { + T* pOldStorage = mStorage; + T* pNewStorage = new T[newCapasity]; + + std::memcpy(pNewStorage, pOldStorage, mSize * sizeof(T)); + + mStorage = pNewStorage; + mCapasity = newCapasity; + + if (pOldStorage != mInplaceStorage) + delete [] pOldStorage; + } + + void push_back_and_grow(const T& item) + { + grow(mCapasity + Capasity); + + mStorage[mSize++] = item; + } + + T* mStorage; + unsigned int mSize; + unsigned int mCapasity; + T mInplaceStorage[Capasity]; +}; + +} // end namespace Assimp + +#endif // !! AI_SMALLVECTOR_H_INC From f0243cc7f3f548bada536f8426ce83cf7100a9f7 Mon Sep 17 00:00:00 2001 From: napina Date: Sun, 22 Mar 2020 15:58:12 +0200 Subject: [PATCH 05/10] Changed AI_LMW_MAX_WEIGHTS*2 to 8 which is same thing. --- code/PostProcessing/LimitBoneWeightsProcess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PostProcessing/LimitBoneWeightsProcess.cpp b/code/PostProcessing/LimitBoneWeightsProcess.cpp index dc4d658ec..f2e615667 100644 --- a/code/PostProcessing/LimitBoneWeightsProcess.cpp +++ b/code/PostProcessing/LimitBoneWeightsProcess.cpp @@ -103,7 +103,7 @@ void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh) return; // collect all bone weights per vertex - typedef SmallVector VertexWeightArray; + typedef SmallVector VertexWeightArray; typedef std::vector WeightsPerVertex; WeightsPerVertex vertexWeights(pMesh->mNumVertices); unsigned int maxVertexWeights = 0; From 788f2f244efb67db735b81a032765a812b7e39c7 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 21 Apr 2020 08:50:51 +0200 Subject: [PATCH 06/10] Adapt code - Reformatting based on clang-format rules - Add usage of size_t instead of unsigned int for sizes - Fix typo in naming --- include/assimp/SmallVector.h | 76 ++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/include/assimp/SmallVector.h b/include/assimp/SmallVector.h index ada241dda..d3a3e57a3 100644 --- a/include/assimp/SmallVector.h +++ b/include/assimp/SmallVector.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2020, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -57,89 +56,82 @@ namespace Assimp { /** \brief Small vector with inplace storage. Reduces heap allocations when list is shorter than initial capasity */ -template -class SmallVector -{ +template +class SmallVector { public: - SmallVector() - : mStorage(mInplaceStorage) - , mSize(0) - , mCapasity(Capasity) - { + SmallVector() : + mStorage(mInplaceStorage), + mSize(0), + mCapacity(Capasity) { + // empty } - ~SmallVector() - { + ~SmallVector() { if (mStorage != mInplaceStorage) { delete [] mStorage; } } - void push_back(const T& item) - { - if (mSize < mCapasity) { + void push_back(const T& item) { + if (mSize < mCapacity) { mStorage[mSize++] = item; + return; } - else push_back_and_grow(item); + + push_back_and_grow(item); } - void resize(unsigned int newSize) - { - if (newSize > mCapasity) + void resize(unsigned int newSize) { + if (newSize > mCapacity) { grow(newSize); + } mSize = newSize; } - unsigned int size() const - { + size_t size() const { return mSize; } - T* begin() - { + T* begin() { return mStorage; } - T* end() - { + T* end() { return &mStorage[mSize]; } - T* begin() const - { + T* begin() const { return mStorage; } - T* end() const - { + T* end() const { return &mStorage[mSize]; } private: - void grow(unsigned int newCapasity) - { - T* pOldStorage = mStorage; - T* pNewStorage = new T[newCapasity]; + void grow( size_t newCapacity) { + T* oldStorage = mStorage; + T* newStorage = new T[newCapacity]; - std::memcpy(pNewStorage, pOldStorage, mSize * sizeof(T)); + std::memcpy(newStorage, oldStorage, mSize * sizeof(T)); - mStorage = pNewStorage; - mCapasity = newCapasity; + mStorage = newStorage; + mCapacity = newCapacity; - if (pOldStorage != mInplaceStorage) - delete [] pOldStorage; + if (oldStorage != mInplaceStorage) { + delete [] oldStorage; + } } - void push_back_and_grow(const T& item) - { - grow(mCapasity + Capasity); + void push_back_and_grow(const T& item) { + grow(mCapacity + Capacity); mStorage[mSize++] = item; } T* mStorage; - unsigned int mSize; - unsigned int mCapasity; + size_t mSize; + size_t mCapacity; T mInplaceStorage[Capasity]; }; From 428b91154afac68b98eac8b2ee5c7b8476960cc5 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 21 Apr 2020 08:59:40 +0200 Subject: [PATCH 07/10] Adapt smallvector - Add doc ( public header ) - Fix type error --- include/assimp/SmallVector.h | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/include/assimp/SmallVector.h b/include/assimp/SmallVector.h index d3a3e57a3..a18c72dab 100644 --- a/include/assimp/SmallVector.h +++ b/include/assimp/SmallVector.h @@ -53,12 +53,16 @@ Based on CppCon 2016: Chandler Carruth "High Performance Code 201: Hybrid Data S namespace Assimp { // -------------------------------------------------------------------------------------------- -/** \brief Small vector with inplace storage. Reduces heap allocations when list is shorter -than initial capasity - */ +/// @brief Small vector with inplace storage. +/// +/// Reduces heap allocations when list is shorter. It uses a small array for a dedicated size. +/// When the growing gets bigger than this small cache a dynamic growing algorithm will be +/// used. +// -------------------------------------------------------------------------------------------- template class SmallVector { public: + /// @brief The default class constructor. SmallVector() : mStorage(mInplaceStorage), mSize(0), @@ -66,12 +70,15 @@ public: // empty } + /// @brief The class destructor. ~SmallVector() { if (mStorage != mInplaceStorage) { delete [] mStorage; } } + /// @brief Will push a new item. The capacity will grow in case of a too small capacity. + /// @param item [in] The item to push at the end of the vector. void push_back(const T& item) { if (mSize < mCapacity) { mStorage[mSize++] = item; @@ -81,33 +88,50 @@ public: push_back_and_grow(item); } - void resize(unsigned int newSize) { + /// @brief Will resize the vector. + /// @param newSize [in] The new size. + void resize(size_t newSize) { if (newSize > mCapacity) { grow(newSize); } mSize = newSize; } + /// @brief Returns the current size of the vector. + /// @return The current size. size_t size() const { return mSize; } + /// @brief Returns a pointer to the first item. + /// @return The first item as a pointer. T* begin() { return mStorage; } + /// @brief Returns a pointer to the end. + /// @return The end as a pointer. T* end() { return &mStorage[mSize]; } + /// @brief Returns a const pointer to the first item. + /// @return The first item as a const pointer. T* begin() const { return mStorage; } + /// @brief Returns a const pointer to the end. + /// @return The end as a const pointer. T* end() const { return &mStorage[mSize]; } + SmallVector(const SmallVector &) = delete; + SmallVector(SmallVector &&) = delete; + SmallVector &operator = (const SmallVector &) = delete; + SmallVector &operator = (SmallVector &&) = delete; + private: void grow( size_t newCapacity) { T* oldStorage = mStorage; From 843ca6e3861e466ff2fb276ba79f9366be62db02 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 21 Apr 2020 15:50:17 +0200 Subject: [PATCH 08/10] Fix typo --- include/assimp/SmallVector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/SmallVector.h b/include/assimp/SmallVector.h index a18c72dab..4bb012004 100644 --- a/include/assimp/SmallVector.h +++ b/include/assimp/SmallVector.h @@ -156,7 +156,7 @@ private: T* mStorage; size_t mSize; size_t mCapacity; - T mInplaceStorage[Capasity]; + T mInplaceStorage[Capacity]; }; } // end namespace Assimp From 232761be02c8256e578bfc6ed0e1478ee230ab9d Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 21 Apr 2020 16:09:11 +0200 Subject: [PATCH 09/10] Fix another typo --- include/assimp/SmallVector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/SmallVector.h b/include/assimp/SmallVector.h index 4bb012004..4e0c200e2 100644 --- a/include/assimp/SmallVector.h +++ b/include/assimp/SmallVector.h @@ -66,7 +66,7 @@ public: SmallVector() : mStorage(mInplaceStorage), mSize(0), - mCapacity(Capasity) { + mCapacity(Capacity) { // empty } From c36b028412cb36d04912917b58489ea03e2f2e48 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 21 Apr 2020 16:39:18 +0200 Subject: [PATCH 10/10] fix type error for template deduction. --- code/PostProcessing/LimitBoneWeightsProcess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PostProcessing/LimitBoneWeightsProcess.cpp b/code/PostProcessing/LimitBoneWeightsProcess.cpp index f2e615667..5b8934159 100644 --- a/code/PostProcessing/LimitBoneWeightsProcess.cpp +++ b/code/PostProcessing/LimitBoneWeightsProcess.cpp @@ -106,7 +106,7 @@ void LimitBoneWeightsProcess::ProcessMesh(aiMesh* pMesh) typedef SmallVector VertexWeightArray; typedef std::vector WeightsPerVertex; WeightsPerVertex vertexWeights(pMesh->mNumVertices); - unsigned int maxVertexWeights = 0; + size_t maxVertexWeights = 0; for (unsigned int b = 0; b < pMesh->mNumBones; ++b) {