Browse Source

ENABLE_THUMBNAIL_GENERATOR -> some other refactoring

Enrico Turri 5 years ago
parent
commit
3dd46f2e03
2 changed files with 8 additions and 52 deletions
  1. 4 21
      src/slic3r/GUI/Camera.cpp
  2. 4 31
      src/slic3r/GUI/GLCanvas3D.cpp

+ 4 - 21
src/slic3r/GUI/Camera.cpp

@@ -367,27 +367,10 @@ std::pair<double, double> Camera::calc_tight_frustrum_zs_around(const BoundingBo
 
     while (true)
     {
-        ret = std::make_pair(DBL_MAX, -DBL_MAX);
-
-        // box vertices in world space
-        std::vector<Vec3d> vertices;
-        vertices.reserve(8);
-        vertices.push_back(box.min);
-        vertices.emplace_back(box.max(0), box.min(1), box.min(2));
-        vertices.emplace_back(box.max(0), box.max(1), box.min(2));
-        vertices.emplace_back(box.min(0), box.max(1), box.min(2));
-        vertices.emplace_back(box.min(0), box.min(1), box.max(2));
-        vertices.emplace_back(box.max(0), box.min(1), box.max(2));
-        vertices.push_back(box.max);
-        vertices.emplace_back(box.min(0), box.max(1), box.max(2));
-
-        // set the Z range in eye coordinates (negative Zs are in front of the camera)
-        for (const Vec3d& v : vertices)
-        {
-            double z = -(m_view_matrix * v)(2);
-            ret.first = std::min(ret.first, z);
-            ret.second = std::max(ret.second, z);
-        }
+        // box in eye space
+        BoundingBoxf3 eye_box = box.transformed(m_view_matrix);
+        ret.first = -eye_box.max(2);
+        ret.second = -eye_box.min(2);
 
         // apply margin
         ret.first -= FrustrumZMargin;

+ 4 - 31
src/slic3r/GUI/GLCanvas3D.cpp

@@ -3928,38 +3928,11 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
     if (show_bed)
     {
         // extends the near and far z of the frustrum to avoid the bed being clipped
-        BoundingBoxf3 bed_box = m_bed.get_bounding_box(true);
-
-        // bed box vertices in world space
-        std::vector<Vec3d> vertices;
-        vertices.reserve(8);
-        vertices.push_back(bed_box.min);
-        vertices.emplace_back(bed_box.max(0), bed_box.min(1), bed_box.min(2));
-        vertices.emplace_back(bed_box.max(0), bed_box.max(1), bed_box.min(2));
-        vertices.emplace_back(bed_box.min(0), bed_box.max(1), bed_box.min(2));
-        vertices.emplace_back(bed_box.min(0), bed_box.min(1), bed_box.max(2));
-        vertices.emplace_back(bed_box.max(0), bed_box.min(1), bed_box.max(2));
-        vertices.push_back(bed_box.max);
-        vertices.emplace_back(bed_box.min(0), bed_box.max(1), bed_box.max(2));
-
-        double bed_box_min_z = DBL_MAX;
-        double bed_box_max_z = -DBL_MAX;
-        Transform3d view_matrix = camera.get_view_matrix();
-        for (const Vec3d& v : vertices)
-        {
-            Vec3d eye_v = view_matrix * v;
-            if (eye_v(2) < 0.0)
-            {
-                bed_box_min_z = std::min(bed_box_min_z, -eye_v(2));
-                bed_box_max_z = std::max(bed_box_max_z, -eye_v(2));
-            }
-        }
-
-        if (bed_box_min_z != DBL_MAX)
-            near_z = bed_box_min_z;
 
-        if (bed_box_max_z != -DBL_MAX)
-            far_z = bed_box_max_z;
+        // box in eye space
+        BoundingBoxf3 t_bed_box = m_bed.get_bounding_box(true).transformed(camera.get_view_matrix());
+        near_z = -t_bed_box.max(2);
+        far_z = -t_bed_box.min(2);
     }
 
     camera.apply_projection(box, near_z, far_z);