Count re-used vertices

This commit is contained in:
Marc Gilleron 2019-04-23 00:14:20 +01:00
parent 0e569df945
commit 1070acf0be
2 changed files with 8 additions and 1 deletions

View File

@ -58,6 +58,7 @@ void MeshBuilder::clear() {
_normals.clear(); _normals.clear();
_indices.clear(); _indices.clear();
_position_to_index.clear(); _position_to_index.clear();
_reused_vertices = 0;
} }
} // namespace dmc } // namespace dmc

View File

@ -11,14 +11,17 @@ namespace dmc {
// Faster than SurfaceTool, only does what is needed to build a smooth mesh // Faster than SurfaceTool, only does what is needed to build a smooth mesh
class MeshBuilder { class MeshBuilder {
public: public:
MeshBuilder() :
_reused_vertices(0) {}
inline void add_vertex(Vector3 position, Vector3 normal) { inline void add_vertex(Vector3 position, Vector3 normal) {
int i = 0; int i = 0;
// TODO Debug this to see if it's effectively indexing
if (_position_to_index.find(position) != _position_to_index.end()) { if (_position_to_index.find(position) != _position_to_index.end()) {
i = _position_to_index[position]; i = _position_to_index[position];
++_reused_vertices;
} else { } else {
@ -35,11 +38,14 @@ public:
Ref<ArrayMesh> commit(bool wireframe); Ref<ArrayMesh> commit(bool wireframe);
void clear(); void clear();
int get_reused_vertex_count() const { return _reused_vertices; }
private: private:
std::vector<Vector3> _positions; std::vector<Vector3> _positions;
std::vector<Vector3> _normals; std::vector<Vector3> _normals;
std::vector<int> _indices; std::vector<int> _indices;
std::map<Vector3, int> _position_to_index; std::map<Vector3, int> _position_to_index;
int _reused_vertices;
}; };
} // namespace dmc } // namespace dmc