ENABLE_THUMBNAIL_GENERATOR -> some other refactoring
This commit is contained in:
parent
ddd1df1552
commit
3dd46f2e03
2 changed files with 8 additions and 52 deletions
|
@ -367,27 +367,10 @@ std::pair<double, double> Camera::calc_tight_frustrum_zs_around(const BoundingBo
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
ret = std::make_pair(DBL_MAX, -DBL_MAX);
|
// box in eye space
|
||||||
|
BoundingBoxf3 eye_box = box.transformed(m_view_matrix);
|
||||||
// box vertices in world space
|
ret.first = -eye_box.max(2);
|
||||||
std::vector<Vec3d> vertices;
|
ret.second = -eye_box.min(2);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply margin
|
// apply margin
|
||||||
ret.first -= FrustrumZMargin;
|
ret.first -= FrustrumZMargin;
|
||||||
|
|
|
@ -3928,38 +3928,11 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
|
||||||
if (show_bed)
|
if (show_bed)
|
||||||
{
|
{
|
||||||
// extends the near and far z of the frustrum to avoid the bed being clipped
|
// 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
|
// box in eye space
|
||||||
std::vector<Vec3d> vertices;
|
BoundingBoxf3 t_bed_box = m_bed.get_bounding_box(true).transformed(camera.get_view_matrix());
|
||||||
vertices.reserve(8);
|
near_z = -t_bed_box.max(2);
|
||||||
vertices.push_back(bed_box.min);
|
far_z = -t_bed_box.min(2);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
camera.apply_projection(box, near_z, far_z);
|
camera.apply_projection(box, near_z, far_z);
|
||||||
|
|
Loading…
Reference in a new issue