From f6f0be47eaecfebc29fe9e9221ee437607d3b820 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Tue, 9 Apr 2019 12:35:05 +0100 Subject: [PATCH] obj import hash fix --- Editor/ModelImporter_OBJ.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index f0a9ea524..79fb867cd 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -15,6 +15,13 @@ using namespace wiECS; // Transform the data from OBJ space to engine-space: static const bool transform_to_LH = true; +template +inline void hash_combine(std::size_t& seed, const T& v) +{ + std::hash 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{}(index.vertex_index), - hash{}(index.normal_index), - hash{}(index.texcoord_index), - hash{}(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) {