mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 07:27:41 -06:00
Gizmos refactoring - Removed GLModels defined into GLGizmoBase, and mostly unused, to avoid wasting GPU memory. Use a shared GLModel for Gizmos inheriting from GLGizmoPainterBase. Initialization of GLModels moved from constructor to render methods
(cherry picked from commit prusa3d/PrusaSlicer@e3d5cd445c)
This commit is contained in:
parent
874f39aac1
commit
b7989e3b2f
5 changed files with 21 additions and 28 deletions
|
@ -149,8 +149,7 @@ void GLGizmoBase::set_icon_filename(const std::string &filename) {
|
|||
|
||||
void GLGizmoBase::set_hover_id(int id)
|
||||
{
|
||||
if (m_grabbers.empty() || (id < (int)m_grabbers.size()))
|
||||
{
|
||||
if (m_grabbers.empty() || id < (int)m_grabbers.size()) {
|
||||
m_hover_id = id;
|
||||
on_set_hover_id();
|
||||
}
|
||||
|
|
|
@ -18,17 +18,21 @@
|
|||
|
||||
namespace Slic3r::GUI {
|
||||
|
||||
std::shared_ptr<GLIndexedVertexArray> GLGizmoPainterBase::s_sphere = nullptr;
|
||||
|
||||
GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
|
||||
: GLGizmoBase(parent, icon_filename, sprite_id)
|
||||
{
|
||||
// Make sphere and save it into a vertex buffer.
|
||||
m_vbo_sphere.load_its_flat_shading(its_make_sphere(1., (2*M_PI)/24.));
|
||||
m_vbo_sphere.finalize_geometry(true);
|
||||
m_vertical_only = false;
|
||||
m_horizontal_only = false;
|
||||
}
|
||||
|
||||
GLGizmoPainterBase::~GLGizmoPainterBase()
|
||||
{
|
||||
if (s_sphere != nullptr && s_sphere->has_VBOs())
|
||||
s_sphere->release_geometry();
|
||||
}
|
||||
|
||||
void GLGizmoPainterBase::set_painter_gizmo_data(const Selection& selection)
|
||||
{
|
||||
if (m_state != On)
|
||||
|
@ -236,6 +240,12 @@ void GLGizmoPainterBase::render_cursor_circle()
|
|||
|
||||
void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const
|
||||
{
|
||||
if (s_sphere == nullptr) {
|
||||
s_sphere = std::make_shared<GLIndexedVertexArray>();
|
||||
s_sphere->load_its_flat_shading(its_make_sphere(1.0, double(PI) / 12.0));
|
||||
s_sphere->finalize_geometry(true);
|
||||
}
|
||||
|
||||
const Transform3d complete_scaling_matrix_inverse = Geometry::Transformation(trafo).get_matrix(true, true, false, true).inverse();
|
||||
const bool is_left_handed = Geometry::Transformation(trafo).is_left_handed();
|
||||
|
||||
|
@ -257,7 +267,8 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const
|
|||
render_color = this->get_cursor_sphere_right_button_color();
|
||||
glsafe(::glColor4fv(render_color.data()));
|
||||
|
||||
m_vbo_sphere.render();
|
||||
assert(s_sphere != nullptr);
|
||||
s_sphere->render();
|
||||
|
||||
if (is_left_handed)
|
||||
glFrontFace(GL_CCW);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <cereal/types/vector.hpp>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace Slic3r::GUI {
|
||||
|
@ -217,7 +218,7 @@ private:
|
|||
void on_render_for_picking() override {}
|
||||
public:
|
||||
GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
|
||||
~GLGizmoPainterBase() override = default;
|
||||
virtual ~GLGizmoPainterBase() override;
|
||||
virtual void set_painter_gizmo_data(const Selection& selection);
|
||||
virtual bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
|
||||
|
||||
|
@ -341,7 +342,7 @@ private:
|
|||
const Camera& camera,
|
||||
const std::vector<Transform3d>& trafo_matrices) const;
|
||||
|
||||
GLIndexedVertexArray m_vbo_sphere;
|
||||
static std::shared_ptr<GLIndexedVertexArray> s_sphere;
|
||||
|
||||
bool m_internal_stack_active = false;
|
||||
bool m_schedule_update = false;
|
||||
|
|
|
@ -31,20 +31,6 @@ GLGizmoRotate::GLGizmoRotate(GLCanvas3D& parent, GLGizmoRotate::Axis axis)
|
|||
, m_axis(axis)
|
||||
{}
|
||||
|
||||
GLGizmoRotate::GLGizmoRotate(const GLGizmoRotate& other)
|
||||
: GLGizmoBase(other.m_parent, other.m_icon_filename, other.m_sprite_id)
|
||||
, m_axis(other.m_axis)
|
||||
, m_angle(other.m_angle)
|
||||
, m_center(other.m_center)
|
||||
, m_radius(other.m_radius)
|
||||
, m_snap_coarse_in_radius(other.m_snap_coarse_in_radius)
|
||||
, m_snap_coarse_out_radius(other.m_snap_coarse_out_radius)
|
||||
, m_snap_fine_in_radius(other.m_snap_fine_in_radius)
|
||||
, m_snap_fine_out_radius(other.m_snap_fine_out_radius)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GLGizmoRotate::set_angle(double angle)
|
||||
{
|
||||
if (std::abs(angle - 2.0 * double(PI)) < EPSILON)
|
||||
|
@ -513,13 +499,10 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, cons
|
|||
//BBS: GUI refactor: add obj manipulation
|
||||
GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id, GizmoObjectManipulation* obj_manipulation)
|
||||
: GLGizmoBase(parent, icon_filename, sprite_id)
|
||||
, m_gizmos({ GLGizmoRotate(parent, GLGizmoRotate::X), GLGizmoRotate(parent, GLGizmoRotate::Y), GLGizmoRotate(parent, GLGizmoRotate::Z) })
|
||||
//BBS: GUI refactor: add obj manipulation
|
||||
, m_object_manipulation(obj_manipulation)
|
||||
{
|
||||
m_gizmos.emplace_back(parent, GLGizmoRotate::X);
|
||||
m_gizmos.emplace_back(parent, GLGizmoRotate::Y);
|
||||
m_gizmos.emplace_back(parent, GLGizmoRotate::Z);
|
||||
|
||||
for (unsigned int i = 0; i < 3; ++i) {
|
||||
m_gizmos[i].set_group_id(i);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ private:
|
|||
|
||||
public:
|
||||
GLGizmoRotate(GLCanvas3D& parent, Axis axis);
|
||||
GLGizmoRotate(const GLGizmoRotate& other);
|
||||
virtual ~GLGizmoRotate() = default;
|
||||
|
||||
double get_angle() const { return m_angle; }
|
||||
|
@ -94,7 +93,7 @@ class GLGizmoRotate3D : public GLGizmoBase
|
|||
{
|
||||
// BBS: change to protected for subclass access
|
||||
protected:
|
||||
std::vector<GLGizmoRotate> m_gizmos;
|
||||
std::array<GLGizmoRotate, 3> m_gizmos;
|
||||
|
||||
//BBS: add size adjust related
|
||||
GizmoObjectManipulation* m_object_manipulation;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue