Clipping plane can now handle multiple-part objects
This commit is contained in:
parent
fe57826695
commit
c32fa67523
2 changed files with 41 additions and 23 deletions
|
@ -284,15 +284,24 @@ void ObjectClipper::on_update()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// which mesh should be cut?
|
// which mesh should be cut?
|
||||||
const TriangleMesh* mesh = &mo->volumes.front()->mesh();
|
std::vector<const TriangleMesh*> meshes;
|
||||||
bool has_hollowed = get_pool()->hollowed_mesh() && get_pool()->hollowed_mesh()->get_hollowed_mesh();
|
bool has_hollowed = get_pool()->hollowed_mesh() && get_pool()->hollowed_mesh()->get_hollowed_mesh();
|
||||||
if (has_hollowed)
|
if (has_hollowed)
|
||||||
mesh = get_pool()->hollowed_mesh()->get_hollowed_mesh();
|
meshes.push_back(get_pool()->hollowed_mesh()->get_hollowed_mesh());
|
||||||
|
|
||||||
if (mesh != m_old_mesh) {
|
if (meshes.empty()) {
|
||||||
m_clipper.reset(new MeshClipper);
|
for (const ModelVolume* mv : mo->volumes)
|
||||||
m_clipper->set_mesh(*mesh);
|
if (mv->is_model_part())
|
||||||
m_old_mesh = mesh;
|
meshes.push_back(&mv->mesh());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (meshes != m_old_meshes) {
|
||||||
|
m_clippers.clear();
|
||||||
|
for (const TriangleMesh* mesh : meshes) {
|
||||||
|
m_clippers.emplace_back(new MeshClipper);
|
||||||
|
m_clippers.back()->set_mesh(*mesh);
|
||||||
|
}
|
||||||
|
m_old_meshes = meshes;
|
||||||
m_active_inst_bb_radius =
|
m_active_inst_bb_radius =
|
||||||
mo->instance_bounding_box(get_pool()->selection_info()->get_active_instance()).radius();
|
mo->instance_bounding_box(get_pool()->selection_info()->get_active_instance()).radius();
|
||||||
//if (has_hollowed && m_clp_ratio != 0.)
|
//if (has_hollowed && m_clp_ratio != 0.)
|
||||||
|
@ -303,8 +312,8 @@ void ObjectClipper::on_update()
|
||||||
|
|
||||||
void ObjectClipper::on_release()
|
void ObjectClipper::on_release()
|
||||||
{
|
{
|
||||||
m_clipper.reset();
|
m_clippers.clear();
|
||||||
m_old_mesh = nullptr;
|
m_old_meshes.clear();
|
||||||
m_clp.reset();
|
m_clp.reset();
|
||||||
m_clp_ratio = 0.;
|
m_clp_ratio = 0.;
|
||||||
|
|
||||||
|
@ -317,21 +326,30 @@ void ObjectClipper::render_cut() const
|
||||||
const SelectionInfo* sel_info = get_pool()->selection_info();
|
const SelectionInfo* sel_info = get_pool()->selection_info();
|
||||||
const ModelObject* mo = sel_info->model_object();
|
const ModelObject* mo = sel_info->model_object();
|
||||||
Geometry::Transformation inst_trafo = mo->instances[sel_info->get_active_instance()]->get_transformation();
|
Geometry::Transformation inst_trafo = mo->instances[sel_info->get_active_instance()]->get_transformation();
|
||||||
Geometry::Transformation vol_trafo = mo->volumes.front()->get_transformation();
|
|
||||||
Geometry::Transformation trafo = inst_trafo * vol_trafo;
|
|
||||||
trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., sel_info->get_sla_shift()));
|
|
||||||
|
|
||||||
m_clipper->set_plane(*m_clp);
|
size_t clipper_id = 0;
|
||||||
m_clipper->set_transformation(trafo);
|
for (const ModelVolume* mv : mo->volumes) {
|
||||||
|
if (! mv->is_model_part())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (! m_clipper->get_triangles().empty()) {
|
Geometry::Transformation vol_trafo = mv->get_transformation();
|
||||||
::glPushMatrix();
|
Geometry::Transformation trafo = inst_trafo * vol_trafo;
|
||||||
::glColor3f(1.0f, 0.37f, 0.0f);
|
trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., sel_info->get_sla_shift()));
|
||||||
::glBegin(GL_TRIANGLES);
|
|
||||||
for (const Vec3f& point : m_clipper->get_triangles())
|
auto& clipper = m_clippers[clipper_id];
|
||||||
::glVertex3f(point(0), point(1), point(2));
|
clipper->set_plane(*m_clp);
|
||||||
::glEnd();
|
clipper->set_transformation(trafo);
|
||||||
::glPopMatrix();
|
|
||||||
|
if (! clipper->get_triangles().empty()) {
|
||||||
|
::glPushMatrix();
|
||||||
|
::glColor3f(1.0f, 0.37f, 0.0f);
|
||||||
|
::glBegin(GL_TRIANGLES);
|
||||||
|
for (const Vec3f& point : clipper->get_triangles())
|
||||||
|
::glVertex3f(point(0), point(1), point(2));
|
||||||
|
::glEnd();
|
||||||
|
::glPopMatrix();
|
||||||
|
}
|
||||||
|
++clipper_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,8 +257,8 @@ protected:
|
||||||
void on_release() override;
|
void on_release() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const TriangleMesh* m_old_mesh = nullptr;
|
std::vector<const TriangleMesh*> m_old_meshes;
|
||||||
std::unique_ptr<MeshClipper> m_clipper;
|
std::vector<std::unique_ptr<MeshClipper>> m_clippers;
|
||||||
std::unique_ptr<ClippingPlane> m_clp;
|
std::unique_ptr<ClippingPlane> m_clp;
|
||||||
double m_clp_ratio = 0.;
|
double m_clp_ratio = 0.;
|
||||||
double m_active_inst_bb_radius = 0.;
|
double m_active_inst_bb_radius = 0.;
|
||||||
|
|
Loading…
Add table
Reference in a new issue