obj import hash fix

This commit is contained in:
turanszkij
2019-04-09 12:35:05 +01:00
parent de79f683fe
commit f6f0be47ea
+12 -7
View File
@@ -15,6 +15,13 @@ using namespace wiECS;
// Transform the data from OBJ space to engine-space:
static const bool transform_to_LH = true;
template <class T>
inline void hash_combine(std::size_t& seed, const T& v)
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
void ImportModel_OBJ(const std::string& fileName, Scene& scene)
{
string directory, name;
@@ -164,13 +171,11 @@ void ImportModel_OBJ(const std::string& fileName, Scene& scene)
}
// eliminate duplicate vertices by means of hashing:
size_t hashes[] = {
hash<int>{}(index.vertex_index),
hash<int>{}(index.normal_index),
hash<int>{}(index.texcoord_index),
hash<int>{}(materialIndex),
};
size_t vertexHash = (((hashes[0] ^ (hashes[1] << 1) >> 1) ^ (hashes[2] << 1)) >> 1) ^ (hashes[3] << 1);
size_t vertexHash = 0;
hash_combine(vertexHash, index.vertex_index);
hash_combine(vertexHash, index.normal_index);
hash_combine(vertexHash, index.texcoord_index);
hash_combine(vertexHash, materialIndex);
if (uniqueVertices.count(vertexHash) == 0)
{