Faster Preview View (#15884)

Co-authored-by: Kris Austin <kris.austin@gmail.com>
This commit is contained in:
Ian Bassi
2026-10-02 14:45:58 -03:00
committed by GitHub
co-authored by Kris Austin
parent 4ffba13210
commit 70bc02467b
37 changed files with 1740 additions and 290 deletions
+29 -2
View File
@@ -80,6 +80,7 @@
#include <imgui/imgui_internal.h>
#include <glad/gl.h>
#include <boost/functional/hash.hpp>
#include <boost/log/trivial.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/nowide/cstdio.hpp>
@@ -1759,6 +1760,26 @@ void GCodeViewer::render_scene(int canvas_width, int canvas_height)
m_sequential_view.render_marker(!m_no_render_path, canvas_width, sequential_view_height(canvas_height), m_viewer.get_view_type());
}
size_t GCodeViewer::shadow_casters_signature() const
{
size_t hash = m_viewer.get_vertices_count();
const libvgcode::Interval& visible = m_viewer.get_view_visible_range();
const libvgcode::Interval& layers = m_viewer.get_layers_view_range();
for (size_t value : { size_t(visible[0]), size_t(visible[1]), size_t(layers[0]), size_t(layers[1]) })
boost::hash_combine(hash, value);
for (double value : { m_paths_bounding_box.min.x(), m_paths_bounding_box.min.y(), m_paths_bounding_box.min.z(),
m_paths_bounding_box.max.x(), m_paths_bounding_box.max.y(), m_paths_bounding_box.max.z() })
boost::hash_combine(hash, value);
boost::hash_combine(hash, m_viewer.is_top_layer_only_view_range());
for (size_t i = 0; i < libvgcode::GCODE_EXTRUSION_ROLES_COUNT; ++i)
boost::hash_combine(hash, m_viewer.is_extrusion_role_visible(libvgcode::EGCodeExtrusionRole(i)));
boost::hash_combine(hash, m_viewer.is_option_visible(libvgcode::EOptionType::Travels));
boost::hash_combine(hash, m_viewer.is_option_visible(libvgcode::EOptionType::Wipes));
for (float value : m_clipping_plane)
boost::hash_combine(hash, value);
return hash;
}
void GCodeViewer::render_shadow_casters(const Transform3d& light_view_matrix, const Transform3d& light_projection_matrix, const Vec3d& light_position)
{
if (!has_data())
@@ -1777,6 +1798,11 @@ void GCodeViewer::set_shadow_map(int texture_unit, const Transform3d& light_view
intensity, texel_size);
}
void GCodeViewer::set_light_top_dir(const Vec3d& direction)
{
m_viewer.set_light_top_dir(libvgcode::convert(static_cast<Vec3f>(direction.cast<float>())));
}
void GCodeViewer::set_tone(float exposure, float saturation)
{
m_viewer.set_tone(exposure, saturation);
@@ -1786,9 +1812,10 @@ void GCodeViewer::set_clipping_plane(const ClippingPlane& plane)
{
// Flipped to match ClippingPlane::distance().
const Vec3f normal = -plane.get_normal().cast<float>();
m_viewer.set_clipping_plane(plane.is_active() ?
m_clipping_plane = plane.is_active() ?
std::array<float, 4>{ normal.x(), normal.y(), normal.z(), float(plane.get_offset()) } :
std::array<float, 4>{ 0.0f, 0.0f, 0.0f, 1.0f });
std::array<float, 4>{ 0.0f, 0.0f, 0.0f, 1.0f };
m_viewer.set_clipping_plane(m_clipping_plane);
}
void GCodeViewer::render_overlay(int canvas_width, int canvas_height, int right_margin)