FDM supports gizmo: caching triangle normals in order to increase performance
This commit is contained in:
parent
e2ccc6ec0c
commit
e312f3be43
3 changed files with 16 additions and 14 deletions
|
@ -506,8 +506,10 @@ void GLGizmoFdmSupports::update_vertex_buffers(const ModelVolume* mv,
|
|||
if (status != type)
|
||||
continue;
|
||||
for (int i=0; i<3; ++i)
|
||||
iva.push_geometry(mesh->its.vertices[mesh->its.indices[facet_idx](i)].cast<double>(),
|
||||
MeshRaycaster::get_triangle_normal(mesh->its, facet_idx).cast<double>());
|
||||
iva.push_geometry(
|
||||
mesh->its.vertices[mesh->its.indices[facet_idx](i)].cast<double>(),
|
||||
m_c->raycaster()->raycasters()[mesh_id]->get_triangle_normal(facet_idx).cast<double>()
|
||||
);
|
||||
iva.push_triangle(3*triangle_cnt, 3*triangle_cnt+1, 3*triangle_cnt+2);
|
||||
++triangle_cnt;
|
||||
}
|
||||
|
|
|
@ -95,11 +95,9 @@ void MeshClipper::recalculate_triangles()
|
|||
}
|
||||
|
||||
|
||||
Vec3f MeshRaycaster::get_triangle_normal(const indexed_triangle_set& its, size_t facet_idx)
|
||||
Vec3f MeshRaycaster::get_triangle_normal(size_t facet_idx) const
|
||||
{
|
||||
Vec3f a(its.vertices[its.indices[facet_idx](1)] - its.vertices[its.indices[facet_idx](0)]);
|
||||
Vec3f b(its.vertices[its.indices[facet_idx](2)] - its.vertices[its.indices[facet_idx](0)]);
|
||||
return Vec3f(a.cross(b)).normalized();
|
||||
return m_normals[facet_idx];
|
||||
}
|
||||
|
||||
void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
|
||||
|
@ -218,12 +216,9 @@ Vec3f MeshRaycaster::get_closest_point(const Vec3f& point, Vec3f* normal) const
|
|||
int idx = 0;
|
||||
Vec3d closest_point;
|
||||
m_emesh.squared_distance(point.cast<double>(), idx, closest_point);
|
||||
if (normal) {
|
||||
auto indices = m_emesh.F().row(idx);
|
||||
Vec3d a(m_emesh.V().row(indices(1)) - m_emesh.V().row(indices(0)));
|
||||
Vec3d b(m_emesh.V().row(indices(2)) - m_emesh.V().row(indices(0)));
|
||||
*normal = Vec3f(a.cross(b).cast<float>());
|
||||
}
|
||||
if (normal)
|
||||
*normal = m_normals[idx];
|
||||
|
||||
return closest_point.cast<float>();
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,11 @@ public:
|
|||
// The pointer can be invalidated after constructor returns.
|
||||
MeshRaycaster(const TriangleMesh& mesh)
|
||||
: m_emesh(mesh)
|
||||
{}
|
||||
{
|
||||
m_normals.reserve(mesh.stl.facet_start.size());
|
||||
for (const stl_facet& facet : mesh.stl.facet_start)
|
||||
m_normals.push_back(facet.normal);
|
||||
}
|
||||
|
||||
void line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
|
||||
Vec3d& point, Vec3d& direction) const;
|
||||
|
@ -140,10 +144,11 @@ public:
|
|||
|
||||
Vec3f get_closest_point(const Vec3f& point, Vec3f* normal = nullptr) const;
|
||||
|
||||
static Vec3f get_triangle_normal(const indexed_triangle_set& its, size_t facet_idx);
|
||||
Vec3f get_triangle_normal(size_t facet_idx) const;
|
||||
|
||||
private:
|
||||
sla::EigenMesh3D m_emesh;
|
||||
std::vector<stl_normal> m_normals;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue