SLA gizmo no more uses IGL code directly, all was moved to the new MeshRaycaster class
This commit is contained in:
parent
1dfd8a0e62
commit
6bcafd7c83
4 changed files with 24 additions and 39 deletions
|
@ -296,8 +296,9 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
||||||
// Matrices set, we can render the point mark now.
|
// Matrices set, we can render the point mark now.
|
||||||
// If in editing mode, we'll also render a cone pointing to the sphere.
|
// If in editing mode, we'll also render a cone pointing to the sphere.
|
||||||
if (m_editing_mode) {
|
if (m_editing_mode) {
|
||||||
|
// in case the normal is not yet cached, find and cache it
|
||||||
if (m_editing_cache[i].normal == Vec3f::Zero())
|
if (m_editing_cache[i].normal == Vec3f::Zero())
|
||||||
update_cache_entry_normal(i); // in case the normal is not yet cached, find and cache it
|
m_mesh_raycaster->get_closest_point(m_editing_cache[i].support_point.pos, &m_editing_cache[i].normal);
|
||||||
|
|
||||||
Eigen::Quaterniond q;
|
Eigen::Quaterniond q;
|
||||||
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>());
|
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>());
|
||||||
|
@ -366,17 +367,8 @@ void GLGizmoSlaSupports::update_mesh()
|
||||||
m_its = &m_mesh->its;
|
m_its = &m_mesh->its;
|
||||||
|
|
||||||
// If this is different mesh than last time or if the AABB tree is uninitialized, recalculate it.
|
// If this is different mesh than last time or if the AABB tree is uninitialized, recalculate it.
|
||||||
if (m_model_object_id != m_model_object->id() || (m_AABB.m_left == NULL && m_AABB.m_right == NULL))
|
if (m_model_object_id != m_model_object->id() || ! m_mesh_raycaster)
|
||||||
{
|
|
||||||
//############################šš
|
|
||||||
m_AABB.deinit();
|
|
||||||
m_AABB.init(
|
|
||||||
MapMatrixXfUnaligned(m_its->vertices.front().data(), m_its->vertices.size(), 3),
|
|
||||||
MapMatrixXiUnaligned(m_its->indices.front().data(), m_its->indices.size(), 3));
|
|
||||||
//############################šš
|
|
||||||
|
|
||||||
m_mesh_raycaster.reset(new MeshRaycaster(*m_mesh));
|
m_mesh_raycaster.reset(new MeshRaycaster(*m_mesh));
|
||||||
}
|
|
||||||
|
|
||||||
m_model_object_id = m_model_object->id();
|
m_model_object_id = m_model_object->id();
|
||||||
disable_editing_mode();
|
disable_editing_mode();
|
||||||
|
@ -389,7 +381,7 @@ void GLGizmoSlaSupports::update_mesh()
|
||||||
bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec3f, Vec3f>& pos_and_normal)
|
bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec3f, Vec3f>& pos_and_normal)
|
||||||
{
|
{
|
||||||
// if the gizmo doesn't have the V, F structures for igl, calculate them first:
|
// if the gizmo doesn't have the V, F structures for igl, calculate them first:
|
||||||
if (m_its == nullptr)
|
if (! m_mesh_raycaster)
|
||||||
update_mesh();
|
update_mesh();
|
||||||
|
|
||||||
const Camera& camera = m_parent.get_camera();
|
const Camera& camera = m_parent.get_camera();
|
||||||
|
@ -658,23 +650,6 @@ std::vector<const ConfigOption*> GLGizmoSlaSupports::get_config_options(const st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GLGizmoSlaSupports::update_cache_entry_normal(size_t i) const
|
|
||||||
{
|
|
||||||
int idx = 0;
|
|
||||||
Eigen::Matrix<float, 1, 3> pp = m_editing_cache[i].support_point.pos;
|
|
||||||
Eigen::Matrix<float, 1, 3> cc;
|
|
||||||
m_AABB.squared_distance(
|
|
||||||
MapMatrixXfUnaligned(m_its->vertices.front().data(), m_its->vertices.size(), 3),
|
|
||||||
MapMatrixXiUnaligned(m_its->indices.front().data(), m_its->indices.size(), 3),
|
|
||||||
pp, idx, cc);
|
|
||||||
Vec3f a = (m_its->vertices[m_its->indices[idx](1)] - m_its->vertices[m_its->indices[idx](0)]);
|
|
||||||
Vec3f b = (m_its->vertices[m_its->indices[idx](2)] - m_its->vertices[m_its->indices[idx](0)]);
|
|
||||||
m_editing_cache[i].normal = a.cross(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ClippingPlane GLGizmoSlaSupports::get_sla_clipping_plane() const
|
ClippingPlane GLGizmoSlaSupports::get_sla_clipping_plane() const
|
||||||
{
|
{
|
||||||
if (!m_model_object || m_state == Off || m_clipping_plane_distance == 0.f)
|
if (!m_model_object || m_state == Off || m_clipping_plane_distance == 0.f)
|
||||||
|
@ -1027,8 +1002,7 @@ void GLGizmoSlaSupports::on_set_state()
|
||||||
m_parent.toggle_model_objects_visibility(true);
|
m_parent.toggle_model_objects_visibility(true);
|
||||||
m_normal_cache.clear();
|
m_normal_cache.clear();
|
||||||
m_clipping_plane_distance = 0.f;
|
m_clipping_plane_distance = 0.f;
|
||||||
// Release triangle mesh slicer and the AABB spatial search structure.
|
// Release clippers and the AABB raycaster.
|
||||||
m_AABB.deinit();
|
|
||||||
m_its = nullptr;
|
m_its = nullptr;
|
||||||
m_object_clipper.reset();
|
m_object_clipper.reset();
|
||||||
m_supports_clipper.reset();
|
m_supports_clipper.reset();
|
||||||
|
|
|
@ -4,11 +4,6 @@
|
||||||
#include "GLGizmoBase.hpp"
|
#include "GLGizmoBase.hpp"
|
||||||
#include "slic3r/GUI/GLSelectionRectangle.hpp"
|
#include "slic3r/GUI/GLSelectionRectangle.hpp"
|
||||||
|
|
||||||
// There is an L function in igl that would be overridden by our localization macro - let's undefine it...
|
|
||||||
#undef L
|
|
||||||
#include <igl/AABB.h>
|
|
||||||
#include "slic3r/GUI/I18N.hpp" // ...and redefine again when we are done with the igl code
|
|
||||||
|
|
||||||
#include "libslic3r/SLA/SLACommon.hpp"
|
#include "libslic3r/SLA/SLACommon.hpp"
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
|
|
||||||
|
@ -38,7 +33,6 @@ private:
|
||||||
GLUquadricObj* m_quadric;
|
GLUquadricObj* m_quadric;
|
||||||
typedef Eigen::Map<const Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>> MapMatrixXfUnaligned;
|
typedef Eigen::Map<const Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>> MapMatrixXfUnaligned;
|
||||||
typedef Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>> MapMatrixXiUnaligned;
|
typedef Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::DontAlign>> MapMatrixXiUnaligned;
|
||||||
igl::AABB<MapMatrixXfUnaligned, 3> m_AABB;
|
|
||||||
|
|
||||||
std::unique_ptr<MeshRaycaster> m_mesh_raycaster;
|
std::unique_ptr<MeshRaycaster> m_mesh_raycaster;
|
||||||
const TriangleMesh* m_mesh;
|
const TriangleMesh* m_mesh;
|
||||||
|
@ -101,7 +95,6 @@ private:
|
||||||
void render_clipping_plane(const Selection& selection) const;
|
void render_clipping_plane(const Selection& selection) const;
|
||||||
bool is_mesh_update_necessary() const;
|
bool is_mesh_update_necessary() const;
|
||||||
void update_mesh();
|
void update_mesh();
|
||||||
void update_cache_entry_normal(size_t i) const;
|
|
||||||
bool unsaved_changes() const;
|
bool unsaved_changes() const;
|
||||||
|
|
||||||
bool m_lock_unique_islands = false;
|
bool m_lock_unique_islands = false;
|
||||||
|
|
|
@ -240,11 +240,27 @@ std::vector<unsigned> MeshRaycaster::get_unobscured_idxs(const Geometry::Transfo
|
||||||
if (! is_obscured)
|
if (! is_obscured)
|
||||||
out.push_back(i);
|
out.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Vec3f MeshRaycaster::get_closest_point(const Vec3f& point, Vec3f* normal) const
|
||||||
|
{
|
||||||
|
int idx = 0;
|
||||||
|
Eigen::Matrix<float, 1, 3> closest_point;
|
||||||
|
m_AABB_wrapper->m_AABB.squared_distance(
|
||||||
|
AABBWrapper::MapMatrixXfUnaligned(m_mesh->its.vertices.front().data(), m_mesh->its.vertices.size(), 3),
|
||||||
|
AABBWrapper::MapMatrixXiUnaligned(m_mesh->its.indices.front().data(), m_mesh->its.indices.size(), 3),
|
||||||
|
point, idx, closest_point);
|
||||||
|
if (normal) {
|
||||||
|
igl::Hit imag_hit;
|
||||||
|
imag_hit.id = idx;
|
||||||
|
*normal = m_AABB_wrapper->get_hit_normal(imag_hit);
|
||||||
|
}
|
||||||
|
return closest_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace GUI
|
} // namespace GUI
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
|
@ -103,6 +103,8 @@ public:
|
||||||
std::vector<unsigned> get_unobscured_idxs(const Geometry::Transformation& trafo, const Camera& camera,
|
std::vector<unsigned> get_unobscured_idxs(const Geometry::Transformation& trafo, const Camera& camera,
|
||||||
const std::vector<Vec3f>& points, std::function<bool(const Vec3f&)> fn_ignore_hit) const;
|
const std::vector<Vec3f>& points, std::function<bool(const Vec3f&)> fn_ignore_hit) const;
|
||||||
|
|
||||||
|
Vec3f get_closest_point(const Vec3f& point, Vec3f* normal = nullptr) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// PIMPL wrapper around igl::AABB so I don't have to include the header-only IGL here
|
// PIMPL wrapper around igl::AABB so I don't have to include the header-only IGL here
|
||||||
class AABBWrapper;
|
class AABBWrapper;
|
||||||
|
|
Loading…
Add table
Reference in a new issue