From daef984ac603e10ffff19f99eccccb6815151913 Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Wed, 22 May 2019 20:00:33 +0200 Subject: [PATCH] Optim FindInstancesProcess ComputePositionEpsilon() is a costly function which was called in the inner loop although it only uses data from upper loop. --- code/FindInstancesProcess.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/FindInstancesProcess.cpp b/code/FindInstancesProcess.cpp index be1138116..64907458a 100644 --- a/code/FindInstancesProcess.cpp +++ b/code/FindInstancesProcess.cpp @@ -137,6 +137,11 @@ void FindInstancesProcess::Execute( aiScene* pScene) aiMesh* inst = pScene->mMeshes[i]; hashes[i] = GetMeshHash(inst); + // Find an appropriate epsilon + // to compare position differences against + float epsilon = ComputePositionEpsilon(inst); + epsilon *= epsilon; + for (int a = i-1; a >= 0; --a) { if (hashes[i] == hashes[a]) { @@ -154,12 +159,7 @@ void FindInstancesProcess::Execute( aiScene* pScene) orig->mPrimitiveTypes != inst->mPrimitiveTypes) continue; - // up to now the meshes are equal. find an appropriate - // epsilon to compare position differences against - float epsilon = ComputePositionEpsilon(inst); - epsilon *= epsilon; - - // now compare vertex positions, normals, + // up to now the meshes are equal. Now compare vertex positions, normals, // tangents and bitangents using this epsilon. if (orig->HasPositions()) { if(!CompareArrays(orig->mVertices,inst->mVertices,orig->mNumVertices,epsilon))