diff --git a/libraries/hfm/src/hfm/HFM.h b/libraries/hfm/src/hfm/HFM.h index 419f47d680..07dc17c02c 100644 --- a/libraries/hfm/src/hfm/HFM.h +++ b/libraries/hfm/src/hfm/HFM.h @@ -230,7 +230,7 @@ public: }; -/// Simple Triangle List vertices; std::vector indices; diff --git a/libraries/hfm/src/hfm/HFMModelMath.cpp b/libraries/hfm/src/hfm/HFMModelMath.cpp index 1086fb711c..1aeaf6d2b9 100644 --- a/libraries/hfm/src/hfm/HFMModelMath.cpp +++ b/libraries/hfm/src/hfm/HFMModelMath.cpp @@ -16,6 +16,9 @@ #include +// TODO: Remove after testing +#include + #include #include @@ -144,38 +147,36 @@ ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const s return reweightedDeformers; } - const TriangleListMesh generateTriangleListMesh(const std::vector& srcVertices, const std::vector& srcParts) { TriangleListMesh dest; - // just copy vertices - dest.vertices.insert(dest.vertices.end(), srcVertices.cbegin(), srcVertices.cend()); + // copy vertices for now + dest.vertices = srcVertices; - /* std::vector remap(srcVertices.size()); + std::vector oldToNewIndex(srcVertices.size()); { - std::unordered_map uniqueVertices; - int vi = 0; - int vu = 0; - for (const auto& v : srcVertices) { - auto foundIndex = uniqueVertices.find(v); - if (foundIndex != uniqueVertices.end()) { - remap[vi] = foundIndex->second; + std::unordered_map uniqueVertexToNewIndex; + int oldIndex = 0; + int newIndex = 0; + for (const auto& srcVertex : srcVertices) { + auto foundIndex = uniqueVertexToNewIndex.find(srcVertex); + if (foundIndex != uniqueVertexToNewIndex.end()) { + oldToNewIndex[oldIndex] = foundIndex->second; } else { - uniqueVertices[v] = vu; - remap[vi] = vu; - dest.vertices[vu] = v; - vu++; + uniqueVertexToNewIndex[srcVertex] = newIndex; + oldToNewIndex[oldIndex] = newIndex; + dest.vertices[newIndex] = srcVertex; + ++newIndex; } - ++vi; + ++oldIndex; } - if (uniqueVertices.size() < srcVertices.size()) { - dest.vertices.resize(uniqueVertices.size()); + if (uniqueVertexToNewIndex.size() < srcVertices.size()) { + dest.vertices.resize(uniqueVertexToNewIndex.size()); dest.vertices.shrink_to_fit(); - } } -*/ + auto newIndicesCount = 0; for (const auto& part : srcParts) { newIndicesCount += part.triangleIndices.size() + part.quadTrianglesIndices.size(); @@ -187,18 +188,15 @@ const TriangleListMesh generateTriangleListMesh(const std::vector& sr for (const auto& part : srcParts) { glm::ivec2 spart(i, 0); for (const auto& qti : part.quadTrianglesIndices) { - dest.indices[i] = qti; //remap[qti]; + dest.indices[i] = oldToNewIndex[qti]; ++i; } for (const auto& ti : part.triangleIndices) { - dest.indices[i] = ti; //remap[ti]; + dest.indices[i] = oldToNewIndex[ti]; ++i; } spart.y = i - spart.x; dest.parts.push_back(spart); - - // dest.indices.insert(dest.indices.end(), part.quadTrianglesIndices.cbegin(), part.quadTrianglesIndices.cend()); - // dest.indices.insert(dest.indices.end(), part.triangleIndices.cbegin(), part.triangleIndices.cend()); } } diff --git a/libraries/model-baker/src/model-baker/Baker.cpp b/libraries/model-baker/src/model-baker/Baker.cpp index c6c8be4bdd..f17db7397e 100644 --- a/libraries/model-baker/src/model-baker/Baker.cpp +++ b/libraries/model-baker/src/model-baker/Baker.cpp @@ -65,7 +65,7 @@ namespace baker { for (int i = 0; i < meshesIn.size(); i++) { auto& mesh = meshesIn[i]; - auto meshPointer = const_cast (&mesh); + auto meshPointer = const_cast(&mesh); meshPointer->_vertices = meshPointer->vertices.toStdVector(); indexedTrianglesMeshOut[i] = hfm::generateTriangleListMesh(meshPointer->_vertices, mesh.parts);