From ce6a5e5d561c96ef8db0a5098576d51c7a340633 Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Mon, 23 Apr 2018 11:33:48 +0200 Subject: [PATCH 1/5] ImproveCacheLocality crashes if non triangular faces --- code/ImproveCacheLocality.cpp | 13 ++++++++----- code/VertexTriangleAdjacency.cpp | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/code/ImproveCacheLocality.cpp b/code/ImproveCacheLocality.cpp index cc6e9db46..ac079ade5 100644 --- a/code/ImproveCacheLocality.cpp +++ b/code/ImproveCacheLocality.cpp @@ -276,8 +276,9 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh // so iterate through all vertices of the current triangle const aiFace* pcFace = &pMesh->mFaces[ fidx ]; - for (unsigned int* p = pcFace->mIndices, *p2 = pcFace->mIndices+3;p != p2;++p) { - const unsigned int dp = *p; + unsigned nind = pcFace->mNumIndices; + for (unsigned ind = 0; ind < nind; ind++) { + unsigned dp = pcFace->mIndices[ind]; // the current vertex won't have any free triangles after this step if (ivdx != (int)dp) { @@ -375,9 +376,11 @@ float ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int mesh // sort the output index buffer back to the input array piCSIter = piIBOutput; for (aiFace* pcFace = pMesh->mFaces; pcFace != pcEnd;++pcFace) { - pcFace->mIndices[0] = *piCSIter++; - pcFace->mIndices[1] = *piCSIter++; - pcFace->mIndices[2] = *piCSIter++; + unsigned nind = pcFace->mNumIndices; + unsigned * ind = pcFace->mIndices; + if (nind > 0) ind[0] = *piCSIter++; + if (nind > 1) ind[1] = *piCSIter++; + if (nind > 2) ind[2] = *piCSIter++; } // delete temporary storage diff --git a/code/VertexTriangleAdjacency.cpp b/code/VertexTriangleAdjacency.cpp index 5886ca372..b41fd029d 100644 --- a/code/VertexTriangleAdjacency.cpp +++ b/code/VertexTriangleAdjacency.cpp @@ -88,10 +88,13 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces, *piEnd++ = 0u; // first pass: compute the number of faces referencing each vertex - for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) { - pi[pcFace->mIndices[0]]++; - pi[pcFace->mIndices[1]]++; - pi[pcFace->mIndices[2]]++; + for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) + { + unsigned nind = pcFace->mNumIndices; + unsigned * ind = pcFace->mIndices; + if (nind > 0) pi[ind[0]]++; + if (nind > 1) pi[ind[1]]++; + if (nind > 2) pi[ind[2]]++; } // second pass: compute the final offset table @@ -109,15 +112,12 @@ VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces, this->mAdjacencyTable = new unsigned int[iSum]; iSum = 0; for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace,++iSum) { + unsigned nind = pcFace->mNumIndices; + unsigned * ind = pcFace->mIndices; - unsigned int idx = pcFace->mIndices[0]; - mAdjacencyTable[pi[idx]++] = iSum; - - idx = pcFace->mIndices[1]; - mAdjacencyTable[pi[idx]++] = iSum; - - idx = pcFace->mIndices[2]; - mAdjacencyTable[pi[idx]++] = iSum; + if (nind > 0) mAdjacencyTable[pi[ind[0]]++] = iSum; + if (nind > 1) mAdjacencyTable[pi[ind[1]]++] = iSum; + if (nind > 2) mAdjacencyTable[pi[ind[2]]++] = iSum; } // fourth pass: undo the offset computations made during the third pass // We could do this in a separate buffer, but this would be TIMES slower. From 43dedb6e0980f779ce61240e17d1df064cac65f7 Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Mon, 23 Apr 2018 12:23:12 +0200 Subject: [PATCH 2/5] unit test: missing mNumIndices --- test/unit/utVertexTriangleAdjacency.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/utVertexTriangleAdjacency.cpp b/test/unit/utVertexTriangleAdjacency.cpp index 046ce25f0..dc109f519 100644 --- a/test/unit/utVertexTriangleAdjacency.cpp +++ b/test/unit/utVertexTriangleAdjacency.cpp @@ -101,8 +101,11 @@ TEST_F(VTAdjacencyTest, smallDataSet) mesh.mFaces = new aiFace[3]; mesh.mFaces[0].mIndices = new unsigned int[3]; + mesh.mFaces[0].mNumIndices = 3; mesh.mFaces[1].mIndices = new unsigned int[3]; + mesh.mFaces[1].mNumIndices = 3; mesh.mFaces[2].mIndices = new unsigned int[3]; + mesh.mFaces[2].mNumIndices = 3; mesh.mFaces[0].mIndices[0] = 1; mesh.mFaces[0].mIndices[1] = 3; From 2d6782cc9fcf31257225265ae4153dc163ca61dd Mon Sep 17 00:00:00 2001 From: Jeroen Bollen Date: Tue, 24 Apr 2018 16:44:22 +0200 Subject: [PATCH 3/5] Changed 'souces' to 'sources'. There was a typo in the `CMakeLists.txt` where if zlib was not found, it would say "Compiling from souces" instead of "Compiling from sources". Added a 'r' to fix the typo. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index add601d1b..cb407c4b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -311,7 +311,7 @@ IF ( NOT ASSIMP_BUILD_ZLIB ) ENDIF( NOT ASSIMP_BUILD_ZLIB ) IF( NOT ZLIB_FOUND ) - MESSAGE(STATUS "compiling zlib from souces") + MESSAGE(STATUS "compiling zlib from sources") INCLUDE(CheckIncludeFile) INCLUDE(CheckTypeSize) INCLUDE(CheckFunctionExists) From 0fdb79871f8e87abd79301986bc025d5005ef852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven!=20Ragnar=C3=B6k?= Date: Tue, 24 Apr 2018 10:12:30 -0700 Subject: [PATCH 4/5] Use CMAKE_INSTALL_PREFIX as ASSIMP_ROOT_DIR. Since the ASSIMP_LIB_INSTALL_DIR where this CMake config file is installed to may contain multiple nested directories, we should not use it to back-calculate the location of the ASSIMP_ROOT_DIR unless we can take the directory depth into account. Instead use the CMAKE_INSTALL_PREFIX as the ASSIMP_ROOT_DIR at configure-time. This approach is more flexible with respect to install directories but it means that assimp files are not relocatable after installation and I don't think it works if a DESTDIR option is provided when running `make install` after cmake configuration. --- assimp-config.cmake.in | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/assimp-config.cmake.in b/assimp-config.cmake.in index 5031c8f8d..1710cac5d 100644 --- a/assimp-config.cmake.in +++ b/assimp-config.cmake.in @@ -10,10 +10,7 @@ # ASSIMP_LIBRARY_DIRS - link directories # ASSIMP_LIBRARIES - libraries to link plugins with # ASSIMP_Boost_VERSION - the boost version assimp was compiled with -get_filename_component(_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(_PREFIX "${_PREFIX}" PATH) -get_filename_component(_PREFIX "${_PREFIX}" PATH) -get_filename_component(ASSIMP_ROOT_DIR "${_PREFIX}" PATH) +get_filename_component(ASSIMP_ROOT_DIR "@CMAKE_INSTALL_PREFIX@" REALPATH) if( MSVC ) # in order to prevent DLL hell, each of the DLLs have to be suffixed with the major version and msvc prefix From a8077baed5da03e273a2c316f77852fe4071cd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fricoteaux?= Date: Wed, 25 Apr 2018 11:37:56 +0200 Subject: [PATCH 5/5] Add vertex color support to glTF2 export --- code/glTF2Exporter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index e146327ea..0c2677fb2 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -732,6 +732,14 @@ void glTF2Exporter::ExportMeshes() } } + /*************** Vertex colors ****************/ + for (unsigned int indexColorChannel = 0; indexColorChannel < aim->GetNumColorChannels(); ++indexColorChannel) + { + Ref c = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mColors[indexColorChannel], AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, false); + if (c) + p.attributes.color.push_back(c); + } + /*************** Vertices indices ****************/ if (aim->mNumFaces > 0) { std::vector indices;