diff --git a/code/FindInstancesProcess.cpp b/code/FindInstancesProcess.cpp index e4a3541f4..76dfa6434 100644 --- a/code/FindInstancesProcess.cpp +++ b/code/FindInstancesProcess.cpp @@ -175,43 +175,32 @@ void FindInstancesProcess::Execute( aiScene* pScene) // use a constant epsilon for colors and UV coordinates static const float uvEpsilon = 10e-4f; - BOOST_STATIC_ASSERT(4 == AI_MAX_NUMBER_OF_COLOR_SETS); - - // as in JIV: manually unrolled as continue wouldn't work as desired in inner loops - if (orig->mTextureCoords[0]) { - if(!CompareArrays(orig->mTextureCoords[0],inst->mTextureCoords[0],orig->mNumVertices,uvEpsilon)) - continue; - if (orig->mTextureCoords[1]) { - if(!CompareArrays(orig->mTextureCoords[1],inst->mTextureCoords[1],orig->mNumVertices,uvEpsilon)) + { + unsigned int i, end = orig->GetNumUVChannels(); + for(i = 0; i < end; ++i) { + if (!orig->mTextureCoords[i]) { continue; - if (orig->mTextureCoords[2]) { - if(!CompareArrays(orig->mTextureCoords[2],inst->mTextureCoords[2],orig->mNumVertices,uvEpsilon)) - continue; - if (orig->mTextureCoords[3]) { - if(!CompareArrays(orig->mTextureCoords[3],inst->mTextureCoords[3],orig->mNumVertices,uvEpsilon)) - continue; - } + } + if(!CompareArrays(orig->mTextureCoords[i],inst->mTextureCoords[i],orig->mNumVertices,uvEpsilon)) { + break; } } - } - - BOOST_STATIC_ASSERT(4 == AI_MAX_NUMBER_OF_COLOR_SETS); - - // and the same nasty stuff for vertex colors ... - if (orig->mColors[0]) { - if(!CompareArrays(orig->mColors[0],inst->mColors[0],orig->mNumVertices,uvEpsilon)) + if (i != end) { continue; - if (orig->mTextureCoords[1]) { - if(!CompareArrays(orig->mColors[1],inst->mColors[1],orig->mNumVertices,uvEpsilon)) + } + } + { + unsigned int i, end = orig->GetNumColorChannels(); + for(i = 0; i < end; ++i) { + if (!orig->mColors[i]) { continue; - if (orig->mTextureCoords[2]) { - if(!CompareArrays(orig->mColors[2],inst->mColors[2],orig->mNumVertices,uvEpsilon)) - continue; - if (orig->mTextureCoords[3]) { - if(!CompareArrays(orig->mColors[3],inst->mColors[3],orig->mNumVertices,uvEpsilon)) - continue; - } } + if(!CompareArrays(orig->mColors[i],inst->mColors[i],orig->mNumVertices,uvEpsilon)) { + break; + } + } + if (i != end) { + continue; } } diff --git a/code/JoinVerticesProcess.cpp b/code/JoinVerticesProcess.cpp index 785837759..ff2abd728 100644 --- a/code/JoinVerticesProcess.cpp +++ b/code/JoinVerticesProcess.cpp @@ -115,8 +115,8 @@ void JoinVerticesProcess::Execute( aiScene* pScene) // Unites identical vertices in the given mesh int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) { - BOOST_STATIC_ASSERT( AI_MAX_NUMBER_OF_COLOR_SETS == 4); - BOOST_STATIC_ASSERT( AI_MAX_NUMBER_OF_TEXTURECOORDS == 4); + BOOST_STATIC_ASSERT( AI_MAX_NUMBER_OF_COLOR_SETS == 8); + BOOST_STATIC_ASSERT( AI_MAX_NUMBER_OF_TEXTURECOORDS == 8); // Return early if we don't have any positions if (!pMesh->HasPositions() || !pMesh->HasFaces()) { @@ -168,14 +168,7 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) // Run an optimized code path if we don't have multiple UVs or vertex colors. // This should yield false in more than 99% of all imports ... - const bool complex = ( - pMesh->mTextureCoords[1] || - pMesh->mTextureCoords[2] || - pMesh->mTextureCoords[3] || - pMesh->mColors[0] || - pMesh->mColors[1] || - pMesh->mColors[2] || - pMesh->mColors[3] ); + const bool complex = ( pMesh->GetNumColorChannels() > 0 || pMesh->GetNumUVChannels() > 1); // Now check each vertex if it brings something new to the table for( unsigned int a = 0; a < pMesh->mNumVertices; a++) { @@ -213,22 +206,48 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) // Actually this increases runtime performance slightly, at least if branch // prediction is on our side. if (complex){ - // manually unrolled because continue wouldn't work as desired in an inner loop + // manually unrolled because continue wouldn't work as desired in an inner loop, + // also because some compilers seem to fail the task. Colors and UV coords + // are interleaved since the higher entries are most likely to be + // zero and thus useless. By interleaving the arrays, vertices are, + // on average, rejected earlier. + + if( (uv.texcoords[1] - v.texcoords[1]).SquareLength() > squareEpsilon) + continue; if( GetColorDifference( uv.colors[0], v.colors[0]) > squareEpsilon) continue; + + if( (uv.texcoords[2] - v.texcoords[2]).SquareLength() > squareEpsilon) + continue; if( GetColorDifference( uv.colors[1], v.colors[1]) > squareEpsilon) continue; + + if( (uv.texcoords[3] - v.texcoords[3]).SquareLength() > squareEpsilon) + continue; if( GetColorDifference( uv.colors[2], v.colors[2]) > squareEpsilon) continue; + + if( (uv.texcoords[4] - v.texcoords[4]).SquareLength() > squareEpsilon) + continue; if( GetColorDifference( uv.colors[3], v.colors[3]) > squareEpsilon) continue; - // texture coord matching manually unrolled as well - if( (uv.texcoords[1] - v.texcoords[1]).SquareLength() > squareEpsilon) + if( (uv.texcoords[5] - v.texcoords[5]).SquareLength() > squareEpsilon) continue; - if( (uv.texcoords[2] - v.texcoords[2]).SquareLength() > squareEpsilon) + if( GetColorDifference( uv.colors[4], v.colors[4]) > squareEpsilon) continue; - if( (uv.texcoords[3] - v.texcoords[3]).SquareLength() > squareEpsilon) + + if( (uv.texcoords[6] - v.texcoords[6]).SquareLength() > squareEpsilon) + continue; + if( GetColorDifference( uv.colors[5], v.colors[5]) > squareEpsilon) + continue; + + if( (uv.texcoords[7] - v.texcoords[7]).SquareLength() > squareEpsilon) + continue; + if( GetColorDifference( uv.colors[6], v.colors[6]) > squareEpsilon) + continue; + + if( GetColorDifference( uv.colors[7], v.colors[7]) > squareEpsilon) continue; } diff --git a/include/aiMesh.h b/include/aiMesh.h index 4637535dc..aabf12531 100644 --- a/include/aiMesh.h +++ b/include/aiMesh.h @@ -90,14 +90,14 @@ extern "C" { * Supported number of vertex color sets per mesh. */ #ifndef AI_MAX_NUMBER_OF_COLOR_SETS -# define AI_MAX_NUMBER_OF_COLOR_SETS 0x4 +# define AI_MAX_NUMBER_OF_COLOR_SETS 0x8 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS /** @def AI_MAX_NUMBER_OF_TEXTURECOORDS * Supported number of texture coord sets (UV(W) channels) per mesh */ #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS -# define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x4 +# define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8 #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS // ---------------------------------------------------------------------------