ModelInstance's full 3D transform set as default

This commit is contained in:
Enrico Turri 2018-10-16 09:51:30 +02:00
parent fb6c1a885c
commit 059ab4a05c
20 changed files with 2 additions and 630 deletions

View file

@ -1086,11 +1086,7 @@ void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
#endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_scale(1) = m_starting_scale(1) * ratio;
#else
m_scale(0) = m_starting_scale(1) * ratio;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
}
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
@ -1102,11 +1098,7 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
#endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_scale(2) = m_starting_scale(2) * ratio;
#else
m_scale(0) = m_starting_scale(2) * ratio; // << this is temporary
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
}
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
@ -1490,18 +1482,11 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
else
::glColor4f(0.9f, 0.9f, 0.9f, 0.5f);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (const InstanceData& inst : m_instances) {
Transform3d m = inst.matrix;
m.pretranslate(dragged_offset);
::glPushMatrix();
::glMultMatrixd(m.data());
#else
for (Vec2d offset : m_instances_positions) {
offset += to_2d(dragged_offset);
::glPushMatrix();
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3dv(vertex.data());
@ -1524,15 +1509,9 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
for (unsigned int i = 0; i < m_planes.size(); ++i)
{
::glColor3f(1.0f, 1.0f, picking_color_component(i));
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (const InstanceData& inst : m_instances) {
::glPushMatrix();
::glMultMatrixd(inst.matrix.data());
#else
for (const Vec2d& offset : m_instances_positions) {
::glPushMatrix();
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3dv(vertex.data());
@ -1548,17 +1527,9 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
// ...and save the updated positions of the object instances:
if (m_model_object && !m_model_object->instances.empty()) {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_instances.clear();
#else
m_instances_positions.clear();
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (const auto* instance : m_model_object->instances)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_instances.emplace_back(instance->world_matrix());
#else
m_instances_positions.emplace_back(instance->offset);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
}
if (is_plane_update_necessary())
@ -1572,10 +1543,6 @@ void GLGizmoFlatten::update_planes()
ch.merge(vol->get_convex_hull());
ch = ch.convex_hull_3d();
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
ch.scale(m_model_object->instances.front()->scaling_factor);
ch.rotate_z(m_model_object->instances.front()->rotation);
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& bb_size = ch.bounding_box().size();
double min_bb_face_area = std::min(bb_size(0) * bb_size(1), std::min(bb_size(0) * bb_size(2), bb_size(1) * bb_size(2)));
@ -1741,10 +1708,6 @@ void GLGizmoFlatten::update_planes()
m_source_data.bounding_boxes.clear();
for (const auto& vol : m_model_object->volumes)
m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box());
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor;
m_source_data.rotation = m_model_object->instances.front()->rotation;
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex();
m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]);
}
@ -1756,13 +1719,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
if (m_state != On || !m_model_object || m_model_object->instances.empty())
return false;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size())
#else
if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size()
|| m_model_object->instances.front()->scaling_factor != m_source_data.scaling_factor
|| m_model_object->instances.front()->rotation != m_source_data.rotation)
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
return true;
// now compare the bounding boxes:
@ -1778,7 +1735,6 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
return false;
}
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d GLGizmoFlatten::get_flattening_rotation() const
{
// calculates the rotations in model space, taking in account the scaling factors
@ -1788,13 +1744,6 @@ Vec3d GLGizmoFlatten::get_flattening_rotation() const
m_normal = Vec3d::Zero();
return Vec3d(angles(2), angles(1), angles(0));
}
#else
Vec3d GLGizmoFlatten::get_flattening_normal() const {
Vec3d normal = m_model_object->instances.front()->world_matrix(true).matrix().block(0, 0, 3, 3).inverse() * m_normal;
m_normal = Vec3d::Zero();
return normal.normalized();
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} // namespace GUI
} // namespace Slic3r