Gizmo flatten -> allow for only single instance and let planes follow the instance when moving the object by dragging it on the scene
This commit is contained in:
parent
e1c90c83e8
commit
c205e3fb0c
2 changed files with 35 additions and 46 deletions
|
@ -696,7 +696,7 @@ void ModelObject::reset_volumes_idxs()
|
||||||
{
|
{
|
||||||
v->set_new_unique_id();
|
v->set_new_unique_id();
|
||||||
}
|
}
|
||||||
}//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
}
|
||||||
|
|
||||||
ModelInstance* ModelObject::add_instance()
|
ModelInstance* ModelObject::add_instance()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1464,9 +1464,7 @@ std::string GLGizmoFlatten::on_get_name() const
|
||||||
|
|
||||||
bool GLGizmoFlatten::on_is_activable(const GLCanvas3D::Selection& selection) const
|
bool GLGizmoFlatten::on_is_activable(const GLCanvas3D::Selection& selection) const
|
||||||
{
|
{
|
||||||
return (selection.is_from_single_object()
|
return selection.is_single_full_instance();
|
||||||
&& (selection.is_single_full_instance() || selection.is_multiple_full_instance() || selection.is_single_full_object())
|
|
||||||
&& !selection.is_wipe_tower() && !selection.is_modifier());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoFlatten::on_start_dragging(const GLCanvas3D::Selection& selection)
|
void GLGizmoFlatten::on_start_dragging(const GLCanvas3D::Selection& selection)
|
||||||
|
@ -1480,44 +1478,33 @@ void GLGizmoFlatten::on_start_dragging(const GLCanvas3D::Selection& selection)
|
||||||
|
|
||||||
void GLGizmoFlatten::on_render(const GLCanvas3D::Selection& selection) const
|
void GLGizmoFlatten::on_render(const GLCanvas3D::Selection& selection) const
|
||||||
{
|
{
|
||||||
// The planes are rendered incorrectly when the object is being moved. We better won't render anything in that case.
|
|
||||||
// This indeed has a better solution (to be implemented when there is more time)
|
|
||||||
Vec3d dragged_offset(Vec3d::Zero());
|
|
||||||
if (m_starting_center == Vec3d::Zero())
|
|
||||||
m_starting_center = selection.get_bounding_box().center();
|
|
||||||
dragged_offset = selection.get_bounding_box().center() - m_starting_center;
|
|
||||||
if (dragged_offset.norm() > 0.001)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_GIZMOS_ON_TOP
|
#if ENABLE_GIZMOS_ON_TOP
|
||||||
::glClear(GL_DEPTH_BUFFER_BIT);
|
::glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
#endif // ENABLE_GIZMOS_ON_TOP
|
#endif // ENABLE_GIZMOS_ON_TOP
|
||||||
|
|
||||||
::glEnable(GL_DEPTH_TEST);
|
::glEnable(GL_DEPTH_TEST);
|
||||||
::glEnable(GL_BLEND);
|
::glEnable(GL_BLEND);
|
||||||
|
|
||||||
if (selection.is_from_single_object()) {
|
if (selection.is_single_full_instance())
|
||||||
if (m_model_object) {
|
{
|
||||||
//for (const int instance_idx : instances_list) {
|
const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix();
|
||||||
for (const ModelInstance* inst : m_model_object->instances) {
|
::glPushMatrix();
|
||||||
Transform3d m = inst->get_matrix();
|
::glMultMatrixd(m.data());
|
||||||
for (int i=0; i<(int)m_planes.size(); ++i) {
|
for (int i = 0; i < (int)m_planes.size(); ++i)
|
||||||
if (i == m_hover_id)
|
{
|
||||||
::glColor4f(0.9f, 0.9f, 0.9f, 0.75f);
|
if (i == m_hover_id)
|
||||||
else
|
::glColor4f(0.9f, 0.9f, 0.9f, 0.75f);
|
||||||
::glColor4f(0.9f, 0.9f, 0.9f, 0.5f);
|
else
|
||||||
|
::glColor4f(0.9f, 0.9f, 0.9f, 0.5f);
|
||||||
|
|
||||||
m.pretranslate(dragged_offset);
|
::glBegin(GL_POLYGON);
|
||||||
::glPushMatrix();
|
for (const Vec3d& vertex : m_planes[i].vertices)
|
||||||
::glMultMatrixd(m.data());
|
{
|
||||||
::glBegin(GL_POLYGON);
|
::glVertex3dv(vertex.data());
|
||||||
for (const Vec3d& vertex : m_planes[i].vertices)
|
|
||||||
::glVertex3dv(vertex.data());
|
|
||||||
::glEnd();
|
|
||||||
::glPopMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
::glEnd();
|
||||||
}
|
}
|
||||||
|
::glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
::glEnable(GL_CULL_FACE);
|
::glEnable(GL_CULL_FACE);
|
||||||
|
@ -1529,20 +1516,22 @@ void GLGizmoFlatten::on_render_for_picking(const GLCanvas3D::Selection& selectio
|
||||||
::glDisable(GL_DEPTH_TEST);
|
::glDisable(GL_DEPTH_TEST);
|
||||||
::glDisable(GL_BLEND);
|
::glDisable(GL_BLEND);
|
||||||
|
|
||||||
if (selection.is_from_single_object()) {
|
if (selection.is_single_full_instance())
|
||||||
if (m_model_object)
|
{
|
||||||
for (const ModelInstance* inst : m_model_object->instances) {
|
const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix();
|
||||||
for (int i=0; i<(int)m_planes.size(); ++i) {
|
::glPushMatrix();
|
||||||
::glColor3f(1.0f, 1.0f, picking_color_component(i));
|
::glMultMatrixd(m.data());
|
||||||
::glPushMatrix();
|
for (int i = 0; i < (int)m_planes.size(); ++i)
|
||||||
::glMultMatrixd(inst->get_matrix().data());
|
{
|
||||||
::glBegin(GL_POLYGON);
|
::glColor3f(1.0f, 1.0f, picking_color_component(i));
|
||||||
for (const Vec3d& vertex : m_planes[i].vertices)
|
::glBegin(GL_POLYGON);
|
||||||
::glVertex3dv(vertex.data());
|
for (const Vec3d& vertex : m_planes[i].vertices)
|
||||||
::glEnd();
|
{
|
||||||
::glPopMatrix();
|
::glVertex3dv(vertex.data());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
::glEnd();
|
||||||
|
}
|
||||||
|
::glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
::glEnable(GL_CULL_FACE);
|
::glEnable(GL_CULL_FACE);
|
||||||
|
|
Loading…
Reference in a new issue