Tue, 27 Jul 2021 16:29:00 +0300
Add vertex rendering
#include "vertexmap.h" #include "linetypes/polygonobject.h" VertexMap::VertexMap(const Model *model) : model{model} { connect( model, &Model::dataChanged, this, &VertexMap::build ); connect( model, &Model::rowsInserted, this, &VertexMap::build ); connect( model, &Model::rowsRemoved, this, &VertexMap::build ); this->build(); } void VertexMap::build() { this->map.clear(); this->vertices.clear(); this->model->apply<ldraw::Object>([&](const ldraw::Object* object) { for (int i = 0; i < object->numPoints(); i += 1) { const glm::vec3& point = object->getPoint(i); const unsigned int hash = qHash(point); this->map[hash].insert(object->id); this->vertices[hash] = point; } }); Q_EMIT this->verticesChanged(); } /** * @brief Apply \c fn for all vertices in the map. * @param fn */ void VertexMap::apply(ApplyFunction fn) const { for (auto it = this->map.cbegin(); it != this->map.cend(); ++it) { const glm::vec3& point = this->vertices.at(it->first); fn(point, it->second); } }