------------------------------------------------------------------------------------------------ Executes the post processing step on the given imported data.
| 113 | // ------------------------------------------------------------------------------------------------ |
| 114 | // Executes the post processing step on the given imported data. |
| 115 | void FindInstancesProcess::Execute( aiScene* pScene) |
| 116 | { |
| 117 | ASSIMP_LOG_DEBUG("FindInstancesProcess begin"); |
| 118 | if (pScene->mNumMeshes) { |
| 119 | |
| 120 | // use a pseudo hash for all meshes in the scene to quickly find |
| 121 | // the ones which are possibly equal. This step is executed early |
| 122 | // in the pipeline, so we could, depending on the file format, |
| 123 | // have several thousand small meshes. That's too much for a brute |
| 124 | // everyone-against-everyone check involving up to 10 comparisons |
| 125 | // each. |
| 126 | std::unique_ptr<uint64_t[]> hashes (new uint64_t[pScene->mNumMeshes]); |
| 127 | std::unique_ptr<unsigned int[]> remapping (new unsigned int[pScene->mNumMeshes]); |
| 128 | |
| 129 | unsigned int numMeshesOut = 0; |
| 130 | for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) { |
| 131 | |
| 132 | aiMesh* inst = pScene->mMeshes[i]; |
| 133 | hashes[i] = GetMeshHash(inst); |
| 134 | |
| 135 | // Find an appropriate epsilon |
| 136 | // to compare position differences against |
| 137 | float epsilon = ComputePositionEpsilon(inst); |
| 138 | epsilon *= epsilon; |
| 139 | |
| 140 | for (int a = i-1; a >= 0; --a) { |
| 141 | if (hashes[i] == hashes[a]) |
| 142 | { |
| 143 | aiMesh* orig = pScene->mMeshes[a]; |
| 144 | if (!orig) |
| 145 | continue; |
| 146 | |
| 147 | // check for hash collision .. we needn't check |
| 148 | // the vertex format, it *must* match due to the |
| 149 | // (brilliant) construction of the hash |
| 150 | if (orig->mNumBones != inst->mNumBones || |
| 151 | orig->mNumFaces != inst->mNumFaces || |
| 152 | orig->mNumVertices != inst->mNumVertices || |
| 153 | orig->mMaterialIndex != inst->mMaterialIndex || |
| 154 | orig->mPrimitiveTypes != inst->mPrimitiveTypes) |
| 155 | continue; |
| 156 | |
| 157 | // up to now the meshes are equal. Now compare vertex positions, normals, |
| 158 | // tangents and bitangents using this epsilon. |
| 159 | if (orig->HasPositions()) { |
| 160 | if(!CompareArrays(orig->mVertices,inst->mVertices,orig->mNumVertices,epsilon)) |
| 161 | continue; |
| 162 | } |
| 163 | if (orig->HasNormals()) { |
| 164 | if(!CompareArrays(orig->mNormals,inst->mNormals,orig->mNumVertices,epsilon)) |
| 165 | continue; |
| 166 | } |
| 167 | if (orig->HasTangentsAndBitangents()) { |
| 168 | if (!CompareArrays(orig->mTangents,inst->mTangents,orig->mNumVertices,epsilon) || |
| 169 | !CompareArrays(orig->mBitangents,inst->mBitangents,orig->mNumVertices,epsilon)) |
| 170 | continue; |
| 171 | } |
| 172 |
nothing calls this directly
no test coverage detected