From 1070acf0be7f46b649c86d54e4f31c813b99ad90 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Tue, 23 Apr 2019 00:14:20 +0100 Subject: [PATCH] Count re-used vertices --- dmc/mesh_builder.cpp | 1 + dmc/mesh_builder.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dmc/mesh_builder.cpp b/dmc/mesh_builder.cpp index d3d57e6..fb1332e 100644 --- a/dmc/mesh_builder.cpp +++ b/dmc/mesh_builder.cpp @@ -58,6 +58,7 @@ void MeshBuilder::clear() { _normals.clear(); _indices.clear(); _position_to_index.clear(); + _reused_vertices = 0; } } // namespace dmc diff --git a/dmc/mesh_builder.h b/dmc/mesh_builder.h index 48727ab..25c159c 100644 --- a/dmc/mesh_builder.h +++ b/dmc/mesh_builder.h @@ -11,14 +11,17 @@ namespace dmc { // Faster than SurfaceTool, only does what is needed to build a smooth mesh class MeshBuilder { public: + MeshBuilder() : + _reused_vertices(0) {} + inline void add_vertex(Vector3 position, Vector3 normal) { int i = 0; - // TODO Debug this to see if it's effectively indexing if (_position_to_index.find(position) != _position_to_index.end()) { i = _position_to_index[position]; + ++_reused_vertices; } else { @@ -35,11 +38,14 @@ public: Ref commit(bool wireframe); void clear(); + int get_reused_vertex_count() const { return _reused_vertices; } + private: std::vector _positions; std::vector _normals; std::vector _indices; std::map _position_to_index; + int _reused_vertices; }; } // namespace dmc