1st installment of gizmo scale 3D
This commit is contained in:
parent
53914e05c6
commit
743eee8b6e
4 changed files with 430 additions and 154 deletions
|
@ -287,6 +287,7 @@ inline Pointf3 operator*(double scalar, const Pointf3& p) { return Pointf3(scala
|
|||
inline Pointf3 operator*(const Pointf3& p, double scalar) { return Pointf3(scalar * p.x, scalar * p.y, scalar * p.z); }
|
||||
inline Pointf3 cross(const Pointf3& v1, const Pointf3& v2) { return Pointf3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x); }
|
||||
inline coordf_t dot(const Pointf3& v1, const Pointf3& v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; }
|
||||
inline double length(const Vectorf3 &v) { return ::sqrt(sqr(v.x) + sqr(v.y) + sqr(v.z)); }
|
||||
inline Pointf3 normalize(const Pointf3& v)
|
||||
{
|
||||
coordf_t len = ::sqrt(sqr(v.x) + sqr(v.y) + sqr(v.z));
|
||||
|
|
|
@ -1130,7 +1130,11 @@ GLCanvas3D::Gizmos::~Gizmos()
|
|||
|
||||
bool GLCanvas3D::Gizmos::init()
|
||||
{
|
||||
#if ENABLE_GIZMOS_3D
|
||||
GLGizmoBase* gizmo = new GLGizmoScale3D;
|
||||
#else
|
||||
GLGizmoBase* gizmo = new GLGizmoScale;
|
||||
#endif // ENABLE_GIZMOS_3D
|
||||
if (gizmo == nullptr)
|
||||
return false;
|
||||
|
||||
|
@ -1359,7 +1363,11 @@ float GLCanvas3D::Gizmos::get_scale() const
|
|||
return 1.0f;
|
||||
|
||||
GizmosMap::const_iterator it = m_gizmos.find(Scale);
|
||||
#if ENABLE_GIZMOS_3D
|
||||
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoScale3D*>(it->second)->get_scale_x() : 1.0f;
|
||||
#else
|
||||
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoScale*>(it->second)->get_scale() : 1.0f;
|
||||
#endif // ENABLE_GIZMOS_3D
|
||||
}
|
||||
|
||||
void GLCanvas3D::Gizmos::set_scale(float scale)
|
||||
|
@ -1369,7 +1377,11 @@ void GLCanvas3D::Gizmos::set_scale(float scale)
|
|||
|
||||
GizmosMap::const_iterator it = m_gizmos.find(Scale);
|
||||
if (it != m_gizmos.end())
|
||||
#if ENABLE_GIZMOS_3D
|
||||
reinterpret_cast<GLGizmoScale3D*>(it->second)->set_scale(scale);
|
||||
#else
|
||||
reinterpret_cast<GLGizmoScale*>(it->second)->set_scale(scale);
|
||||
#endif // ENABLE_GIZMOS_3D
|
||||
}
|
||||
|
||||
float GLCanvas3D::Gizmos::get_angle_z() const
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "GLGizmo.hpp"
|
||||
|
||||
#include "../../libslic3r/Utils.hpp"
|
||||
#include "../../libslic3r/BoundingBox.hpp"
|
||||
|
||||
#include <Eigen/Dense>
|
||||
|
||||
|
@ -13,6 +12,10 @@ static const float DEFAULT_BASE_COLOR[3] = { 0.625f, 0.625f, 0.625f };
|
|||
static const float DEFAULT_DRAG_COLOR[3] = { 1.0f, 1.0f, 1.0f };
|
||||
static const float DEFAULT_HIGHLIGHT_COLOR[3] = { 1.0f, 0.38f, 0.0f };
|
||||
|
||||
static const float RED[3] = { 1.0f, 0.0f, 0.0f };
|
||||
static const float GREEN[3] = { 0.0f, 1.0f, 0.0f };
|
||||
static const float BLUE[3] = { 0.0f, 0.0f, 1.0f };
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
|
@ -46,11 +49,6 @@ void GLGizmoBase::Grabber::render(bool hover) const
|
|||
render(render_color);
|
||||
}
|
||||
|
||||
void GLGizmoBase::Grabber::render_for_picking() const
|
||||
{
|
||||
render(color);
|
||||
}
|
||||
|
||||
void GLGizmoBase::Grabber::render(const float* render_color) const
|
||||
{
|
||||
float half_size = dragging ? HalfSize * DraggingScaleFactor : HalfSize;
|
||||
|
@ -94,16 +92,6 @@ GLGizmoBase::GLGizmoBase()
|
|||
::memcpy((void*)m_highlight_color, (const void*)DEFAULT_HIGHLIGHT_COLOR, 3 * sizeof(float));
|
||||
}
|
||||
|
||||
unsigned int GLGizmoBase::get_texture_id() const
|
||||
{
|
||||
return m_textures[m_state].get_id();
|
||||
}
|
||||
|
||||
int GLGizmoBase::get_textures_size() const
|
||||
{
|
||||
return m_textures[Off].get_width();
|
||||
}
|
||||
|
||||
void GLGizmoBase::set_hover_id(int id)
|
||||
{
|
||||
if (m_is_container || (id < (int)m_grabbers.size()))
|
||||
|
@ -145,21 +133,6 @@ void GLGizmoBase::update(const Linef3& mouse_ray)
|
|||
on_update(mouse_ray);
|
||||
}
|
||||
|
||||
void GLGizmoBase::refresh()
|
||||
{
|
||||
on_refresh();
|
||||
}
|
||||
|
||||
void GLGizmoBase::render(const BoundingBoxf3& box) const
|
||||
{
|
||||
on_render(box);
|
||||
}
|
||||
|
||||
void GLGizmoBase::render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
on_render_for_picking(box);
|
||||
}
|
||||
|
||||
float GLGizmoBase::picking_color_component(unsigned int id) const
|
||||
{
|
||||
int color = 254 - (int)id;
|
||||
|
@ -206,11 +179,6 @@ GLGizmoRotate::GLGizmoRotate(GLGizmoRotate::Axis axis)
|
|||
{
|
||||
}
|
||||
|
||||
float GLGizmoRotate::get_angle() const
|
||||
{
|
||||
return m_angle;
|
||||
}
|
||||
|
||||
void GLGizmoRotate::set_angle(float angle)
|
||||
{
|
||||
if (std::abs(angle - 2.0f * PI) < EPSILON)
|
||||
|
@ -242,11 +210,6 @@ bool GLGizmoRotate::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_set_state()
|
||||
{
|
||||
m_keep_initial_values = (m_state == On) ? false : true;
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_update(const Linef3& mouse_ray)
|
||||
{
|
||||
Pointf mouse_pos = mouse_position_in_local_plane(mouse_ray);
|
||||
|
@ -274,11 +237,6 @@ void GLGizmoRotate::on_update(const Linef3& mouse_ray)
|
|||
m_angle = (float)theta;
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_refresh()
|
||||
{
|
||||
m_keep_initial_values = false;
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
@ -488,20 +446,22 @@ void GLGizmoRotate::transform_to_local() const
|
|||
|
||||
Pointf GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) const
|
||||
{
|
||||
float half_pi = 0.5f * (float)PI;
|
||||
|
||||
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
|
||||
|
||||
switch (m_axis)
|
||||
{
|
||||
case X:
|
||||
{
|
||||
m.rotate(Eigen::AngleAxisf(-0.5f * (float)PI, Eigen::Vector3f::UnitZ()));
|
||||
m.rotate(Eigen::AngleAxisf(-0.5f * (float)PI, Eigen::Vector3f::UnitY()));
|
||||
m.rotate(Eigen::AngleAxisf(-half_pi, Eigen::Vector3f::UnitZ()));
|
||||
m.rotate(Eigen::AngleAxisf(-half_pi, Eigen::Vector3f::UnitY()));
|
||||
break;
|
||||
}
|
||||
case Y:
|
||||
{
|
||||
m.rotate(Eigen::AngleAxisf(-(float)PI, Eigen::Vector3f::UnitZ()));
|
||||
m.rotate(Eigen::AngleAxisf(-0.5f * (float)PI, Eigen::Vector3f::UnitX()));
|
||||
m.rotate(Eigen::AngleAxisf(-half_pi, Eigen::Vector3f::UnitX()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -540,48 +500,14 @@ GLGizmoRotate3D::GLGizmoRotate3D()
|
|||
m_z.set_group_id(2);
|
||||
}
|
||||
|
||||
float GLGizmoRotate3D::get_angle_x() const
|
||||
{
|
||||
return m_x.get_angle();
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::set_angle_x(float angle)
|
||||
{
|
||||
m_x.set_angle(angle);
|
||||
}
|
||||
|
||||
float GLGizmoRotate3D::get_angle_y() const
|
||||
{
|
||||
return m_y.get_angle();
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::set_angle_y(float angle)
|
||||
{
|
||||
m_y.set_angle(angle);
|
||||
}
|
||||
|
||||
float GLGizmoRotate3D::get_angle_z() const
|
||||
{
|
||||
return m_z.get_angle();
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::set_angle_z(float angle)
|
||||
{
|
||||
m_z.set_angle(angle);
|
||||
}
|
||||
|
||||
bool GLGizmoRotate3D::on_init()
|
||||
{
|
||||
if (!m_x.init() || !m_y.init() || !m_z.init())
|
||||
return false;
|
||||
|
||||
float red[3] = { 1.0f, 0.0f, 0.0f };
|
||||
float green[3] = { 0.0f, 1.0f, 0.0f };
|
||||
float blue[3] = { 0.0f, 0.0f, 1.0f };
|
||||
|
||||
m_x.set_highlight_color(red);
|
||||
m_y.set_highlight_color(green);
|
||||
m_z.set_highlight_color(blue);
|
||||
m_x.set_highlight_color(RED);
|
||||
m_y.set_highlight_color(GREEN);
|
||||
m_z.set_highlight_color(BLUE);
|
||||
|
||||
std::string path = resources_dir() + "/icons/overlay/";
|
||||
|
||||
|
@ -600,20 +526,6 @@ bool GLGizmoRotate3D::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_set_state()
|
||||
{
|
||||
m_x.set_state(m_state);
|
||||
m_y.set_state(m_state);
|
||||
m_z.set_state(m_state);
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_set_hover_id()
|
||||
{
|
||||
m_x.set_hover_id(m_hover_id == 0 ? 0 : -1);
|
||||
m_y.set_hover_id(m_hover_id == 1 ? 0 : -1);
|
||||
m_z.set_hover_id(m_hover_id == 2 ? 0 : -1);
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_start_dragging()
|
||||
{
|
||||
switch (m_hover_id)
|
||||
|
@ -666,20 +578,6 @@ void GLGizmoRotate3D::on_stop_dragging()
|
|||
}
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_update(const Linef3& mouse_ray)
|
||||
{
|
||||
m_x.update(mouse_ray);
|
||||
m_y.update(mouse_ray);
|
||||
m_z.update(mouse_ray);
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_refresh()
|
||||
{
|
||||
m_x.refresh();
|
||||
m_y.refresh();
|
||||
m_z.refresh();
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
if ((m_hover_id == -1) || (m_hover_id == 0))
|
||||
|
@ -692,13 +590,6 @@ void GLGizmoRotate3D::on_render(const BoundingBoxf3& box) const
|
|||
m_z.render(box);
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
m_x.render_for_picking(box);
|
||||
m_y.render_for_picking(box);
|
||||
m_z.render_for_picking(box);
|
||||
}
|
||||
|
||||
const float GLGizmoScale::Offset = 5.0f;
|
||||
|
||||
GLGizmoScale::GLGizmoScale()
|
||||
|
@ -708,16 +599,6 @@ GLGizmoScale::GLGizmoScale()
|
|||
{
|
||||
}
|
||||
|
||||
float GLGizmoScale::get_scale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
void GLGizmoScale::set_scale(float scale)
|
||||
{
|
||||
m_starting_scale = scale;
|
||||
}
|
||||
|
||||
bool GLGizmoScale::on_init()
|
||||
{
|
||||
std::string path = resources_dir() + "/icons/overlay/";
|
||||
|
@ -810,5 +691,309 @@ void GLGizmoScale::on_render_for_picking(const BoundingBoxf3& box) const
|
|||
render_grabbers_for_picking();
|
||||
}
|
||||
|
||||
const float GLGizmoScale3D::Offset = 5.0f;
|
||||
|
||||
GLGizmoScale3D::GLGizmoScale3D()
|
||||
: GLGizmoBase()
|
||||
, m_scale_x(1.0f)
|
||||
, m_scale_y(1.0f)
|
||||
, m_scale_z(1.0f)
|
||||
, m_starting_scale_x(1.0f)
|
||||
, m_starting_scale_y(1.0f)
|
||||
, m_starting_scale_z(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
bool GLGizmoScale3D::on_init()
|
||||
{
|
||||
std::string path = resources_dir() + "/icons/overlay/";
|
||||
|
||||
std::string filename = path + "scale_off.png";
|
||||
if (!m_textures[Off].load_from_file(filename, false))
|
||||
return false;
|
||||
|
||||
filename = path + "scale_hover.png";
|
||||
if (!m_textures[Hover].load_from_file(filename, false))
|
||||
return false;
|
||||
|
||||
filename = path + "scale_on.png";
|
||||
if (!m_textures[On].load_from_file(filename, false))
|
||||
return false;
|
||||
|
||||
for (unsigned int i = 0; i < 7; ++i)
|
||||
{
|
||||
m_grabbers.push_back(Grabber());
|
||||
}
|
||||
|
||||
float half_pi = 0.5f * (float)PI;
|
||||
|
||||
// x axis
|
||||
m_grabbers[0].angle_y = half_pi;
|
||||
m_grabbers[1].angle_y = half_pi;
|
||||
|
||||
// y axis
|
||||
m_grabbers[2].angle_x = half_pi;
|
||||
m_grabbers[3].angle_x = half_pi;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::on_start_dragging()
|
||||
{
|
||||
if (m_hover_id != -1)
|
||||
m_starting_drag_position = m_grabbers[m_hover_id].center;
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::on_update(const Linef3& mouse_ray)
|
||||
{
|
||||
if ((m_hover_id == 0) || (m_hover_id == 1))
|
||||
do_scale_x(mouse_ray);
|
||||
else if ((m_hover_id == 2) || (m_hover_id == 3))
|
||||
do_scale_y(mouse_ray);
|
||||
else if ((m_hover_id == 4) || (m_hover_id == 5))
|
||||
do_scale_z(mouse_ray);
|
||||
else if (m_hover_id == 6)
|
||||
do_scale_uniform(mouse_ray);
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
Vectorf3 offset_vec((coordf_t)Offset, (coordf_t)Offset, (coordf_t)Offset);
|
||||
|
||||
m_box = BoundingBoxf3(box.min - offset_vec, box.max + offset_vec);
|
||||
const Pointf3& center = m_box.center();
|
||||
|
||||
// x axis
|
||||
m_grabbers[0].center.x = m_box.min.x;
|
||||
m_grabbers[0].center.y = center.y;
|
||||
m_grabbers[0].center.z = center.z;
|
||||
m_grabbers[1].center.x = m_box.max.x;
|
||||
m_grabbers[1].center.y = center.y;
|
||||
m_grabbers[1].center.z = center.z;
|
||||
|
||||
// y axis
|
||||
m_grabbers[2].center.x = center.x;
|
||||
m_grabbers[2].center.y = m_box.min.y;
|
||||
m_grabbers[2].center.z = center.z;
|
||||
m_grabbers[3].center.x = center.x;
|
||||
m_grabbers[3].center.y = m_box.max.y;
|
||||
m_grabbers[3].center.z = center.z;
|
||||
|
||||
// z axis
|
||||
m_grabbers[4].center.x = center.x;
|
||||
m_grabbers[4].center.y = center.y;
|
||||
m_grabbers[4].center.z = m_box.min.z;
|
||||
m_grabbers[5].center.x = center.x;
|
||||
m_grabbers[5].center.y = center.y;
|
||||
m_grabbers[5].center.z = m_box.max.z;
|
||||
|
||||
// uniform
|
||||
m_grabbers[6].center = m_box.min;
|
||||
|
||||
::memcpy((void*)m_grabbers[0].color, (const void*)RED, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[1].color, (const void*)RED, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[2].color, (const void*)GREEN, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[3].color, (const void*)GREEN, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[4].color, (const void*)BLUE, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[5].color, (const void*)BLUE, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[6].color, (const void*)m_highlight_color, 3 * sizeof(float));
|
||||
|
||||
::glLineWidth(2.0f);
|
||||
|
||||
if (m_hover_id == -1)
|
||||
{
|
||||
// draw box
|
||||
::glColor3fv(m_base_color);
|
||||
render_box_x_faces();
|
||||
render_box_y_faces();
|
||||
render_box_z_faces();
|
||||
|
||||
// draw grabbers
|
||||
render_grabbers();
|
||||
}
|
||||
else if ((m_hover_id == 0) || (m_hover_id == 1))
|
||||
{
|
||||
::glColor3fv(m_drag_color);
|
||||
render_box_x_faces();
|
||||
m_grabbers[0].render(true);
|
||||
m_grabbers[1].render(true);
|
||||
}
|
||||
else if ((m_hover_id == 2) || (m_hover_id == 3))
|
||||
{
|
||||
::glColor3fv(m_drag_color);
|
||||
render_box_y_faces();
|
||||
m_grabbers[2].render(true);
|
||||
m_grabbers[3].render(true);
|
||||
}
|
||||
else if ((m_hover_id == 4) || (m_hover_id == 5))
|
||||
{
|
||||
::glColor3fv(m_drag_color);
|
||||
render_box_z_faces();
|
||||
m_grabbers[4].render(true);
|
||||
m_grabbers[5].render(true);
|
||||
}
|
||||
else if (m_hover_id == 6)
|
||||
{
|
||||
::glColor3fv(m_drag_color);
|
||||
render_box_x_faces();
|
||||
render_box_y_faces();
|
||||
render_box_z_faces();
|
||||
m_grabbers[6].render(true);
|
||||
}
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
for (unsigned int i = 0; i < 7; ++i)
|
||||
{
|
||||
m_grabbers[i].color[0] = 1.0f;
|
||||
m_grabbers[i].color[1] = 1.0f;
|
||||
m_grabbers[i].color[2] = picking_color_component(i);
|
||||
}
|
||||
|
||||
render_grabbers_for_picking();
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::render_box_x_faces() const
|
||||
{
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
|
||||
::glEnd();
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::render_box_y_faces() const
|
||||
{
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
|
||||
::glEnd();
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::render_box_z_faces() const
|
||||
{
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
|
||||
::glEnd();
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
|
||||
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
Linef3 transform(const Linef3& line, const Eigen::Transform<float, 3, Eigen::Affine>& t)
|
||||
{
|
||||
Eigen::Matrix<float, 3, 2> world_line;
|
||||
Eigen::Matrix<float, 3, 2> local_line;
|
||||
world_line(0, 0) = (float)line.a.x;
|
||||
world_line(1, 0) = (float)line.a.y;
|
||||
world_line(2, 0) = (float)line.a.z;
|
||||
world_line(0, 1) = (float)line.b.x;
|
||||
world_line(1, 1) = (float)line.b.y;
|
||||
world_line(2, 1) = (float)line.b.z;
|
||||
local_line = t * world_line.colwise().homogeneous();
|
||||
|
||||
return Linef3(Pointf3(local_line(0, 0), local_line(1, 0), local_line(2, 0)), Pointf3(local_line(0, 1), local_line(1, 1), local_line(2, 1)));
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray)
|
||||
{
|
||||
// calculates the intersection of the mouse ray with the plane parallel to plane XY and passing through the box center
|
||||
const Pointf3& center = m_box.center();
|
||||
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
|
||||
m.translate(Eigen::Vector3f(-(float)center.x, -(float)center.y, -(float)center.z));
|
||||
|
||||
Pointf mouse_pos = transform(mouse_ray, m).intersect_plane(0.0);
|
||||
|
||||
coordf_t orig_len = length(m_starting_drag_position - center);
|
||||
coordf_t new_len = length(mouse_pos);
|
||||
coordf_t ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
|
||||
|
||||
m_scale_x = m_starting_scale_x * (float)ratio;
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
|
||||
{
|
||||
// calculates the intersection of the mouse ray with the plane parallel to plane XY and passing through the box center
|
||||
const Pointf3& center = m_box.center();
|
||||
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
|
||||
m.translate(Eigen::Vector3f(-(float)center.x, -(float)center.y, -(float)center.z));
|
||||
|
||||
Pointf mouse_pos = transform(mouse_ray, m).intersect_plane(0.0);
|
||||
|
||||
coordf_t orig_len = length(m_starting_drag_position - center);
|
||||
coordf_t new_len = length(mouse_pos);
|
||||
coordf_t ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
|
||||
|
||||
m_scale_x = m_starting_scale_y * (float)ratio;
|
||||
// m_scale_y = m_starting_scale_y * (float)ratio;
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
||||
{
|
||||
// calculates the intersection of the mouse ray with the plane parallel to plane XZ and passing through the box center
|
||||
const Pointf3& center = m_box.center();
|
||||
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
|
||||
m.rotate(Eigen::AngleAxisf(0.5f * (float)PI, Eigen::Vector3f::UnitX()));
|
||||
m.translate(Eigen::Vector3f(-(float)center.x, -(float)center.y, -(float)center.z));
|
||||
|
||||
Pointf mouse_pos = transform(mouse_ray, m).intersect_plane(0.0);
|
||||
|
||||
coordf_t orig_len = length(m_starting_drag_position - center);
|
||||
coordf_t new_len = length(mouse_pos);
|
||||
coordf_t ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
|
||||
|
||||
m_scale_x = m_starting_scale_z * (float)ratio;
|
||||
// m_scale_z = m_starting_scale_z * (float)ratio;
|
||||
|
||||
if (m_scale_x > 10.0)
|
||||
{
|
||||
int a = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
|
||||
{
|
||||
// calculates the intersection of the mouse ray with the plane parallel to plane XY and passing through the box min point
|
||||
const Pointf3& center = m_box.center();
|
||||
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
|
||||
m.translate(Eigen::Vector3f(-(float)center.x, -(float)center.y, -(float)m_box.min.z));
|
||||
|
||||
Pointf mouse_pos = transform(mouse_ray, m).intersect_plane(0.0);
|
||||
|
||||
coordf_t orig_len = length(m_starting_drag_position - center);
|
||||
coordf_t new_len = length(Vectorf3(mouse_pos.x, mouse_pos.y, m_box.min.z - center.z));
|
||||
coordf_t ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
|
||||
|
||||
m_scale_x = m_starting_scale_y * (float)ratio;
|
||||
m_scale_y = m_starting_scale_y * (float)ratio;
|
||||
m_scale_z = m_starting_scale_z * (float)ratio;
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
#include "../../slic3r/GUI/GLTexture.hpp"
|
||||
#include "../../libslic3r/Point.hpp"
|
||||
#include "../../libslic3r/BoundingBox.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define ENABLE_GIZMOS_3D 1
|
||||
#define ENABLE_GIZMOS_3D 0
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -34,7 +35,7 @@ protected:
|
|||
Grabber();
|
||||
|
||||
void render(bool hover) const;
|
||||
void render_for_picking() const;
|
||||
void render_for_picking() const { render(color); }
|
||||
|
||||
private:
|
||||
void render(const float* render_color) const;
|
||||
|
@ -73,8 +74,8 @@ public:
|
|||
EState get_state() const { return m_state; }
|
||||
void set_state(EState state) { m_state = state; on_set_state(); }
|
||||
|
||||
unsigned int get_texture_id() const;
|
||||
int get_textures_size() const;
|
||||
unsigned int get_texture_id() const { return m_textures[m_state].get_id(); }
|
||||
int get_textures_size() const { return m_textures[Off].get_width(); }
|
||||
|
||||
int get_hover_id() const { return m_hover_id; }
|
||||
void set_hover_id(int id);
|
||||
|
@ -84,10 +85,10 @@ public:
|
|||
void start_dragging();
|
||||
void stop_dragging();
|
||||
void update(const Linef3& mouse_ray);
|
||||
void refresh();
|
||||
void refresh() { on_refresh(); }
|
||||
|
||||
void render(const BoundingBoxf3& box) const;
|
||||
void render_for_picking(const BoundingBoxf3& box) const;
|
||||
void render(const BoundingBoxf3& box) const { on_render(box); }
|
||||
void render_for_picking(const BoundingBoxf3& box) const { on_render_for_picking(box); }
|
||||
|
||||
protected:
|
||||
virtual bool on_init() = 0;
|
||||
|
@ -137,14 +138,14 @@ private:
|
|||
public:
|
||||
explicit GLGizmoRotate(Axis axis);
|
||||
|
||||
float get_angle() const;
|
||||
float get_angle() const { return m_angle; }
|
||||
void set_angle(float angle);
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_set_state();
|
||||
virtual void on_set_state() { m_keep_initial_values = (m_state == On) ? false : true; }
|
||||
virtual void on_update(const Linef3& mouse_ray);
|
||||
virtual void on_refresh();
|
||||
virtual void on_refresh() { m_keep_initial_values = false; }
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
||||
|
||||
|
@ -169,25 +170,50 @@ class GLGizmoRotate3D : public GLGizmoBase
|
|||
public:
|
||||
GLGizmoRotate3D();
|
||||
|
||||
float get_angle_x() const;
|
||||
void set_angle_x(float angle);
|
||||
float get_angle_x() const { return m_x.get_angle(); }
|
||||
void set_angle_x(float angle) { m_x.set_angle(angle); }
|
||||
|
||||
float get_angle_y() const;
|
||||
void set_angle_y(float angle);
|
||||
float get_angle_y() const { return m_y.get_angle(); }
|
||||
void set_angle_y(float angle) { m_y.set_angle(angle); }
|
||||
|
||||
float get_angle_z() const;
|
||||
void set_angle_z(float angle);
|
||||
float get_angle_z() const { return m_z.get_angle(); }
|
||||
void set_angle_z(float angle) { m_z.set_angle(angle); }
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_set_state();
|
||||
virtual void on_set_hover_id();
|
||||
virtual void on_set_state()
|
||||
{
|
||||
m_x.set_state(m_state);
|
||||
m_y.set_state(m_state);
|
||||
m_z.set_state(m_state);
|
||||
}
|
||||
virtual void on_set_hover_id()
|
||||
{
|
||||
m_x.set_hover_id(m_hover_id == 0 ? 0 : -1);
|
||||
m_y.set_hover_id(m_hover_id == 1 ? 0 : -1);
|
||||
m_z.set_hover_id(m_hover_id == 2 ? 0 : -1);
|
||||
}
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_stop_dragging();
|
||||
virtual void on_update(const Linef3& mouse_ray);
|
||||
virtual void on_refresh();
|
||||
virtual void on_update(const Linef3& mouse_ray)
|
||||
{
|
||||
m_x.update(mouse_ray);
|
||||
m_y.update(mouse_ray);
|
||||
m_z.update(mouse_ray);
|
||||
}
|
||||
virtual void on_refresh()
|
||||
{
|
||||
m_x.refresh();
|
||||
m_y.refresh();
|
||||
m_z.refresh();
|
||||
}
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
m_x.render_for_picking(box);
|
||||
m_y.render_for_picking(box);
|
||||
m_z.render_for_picking(box);
|
||||
}
|
||||
};
|
||||
|
||||
class GLGizmoScale : public GLGizmoBase
|
||||
|
@ -202,8 +228,8 @@ class GLGizmoScale : public GLGizmoBase
|
|||
public:
|
||||
GLGizmoScale();
|
||||
|
||||
float get_scale() const;
|
||||
void set_scale(float scale);
|
||||
float get_scale() const { return m_scale; }
|
||||
void set_scale(float scale) { m_starting_scale = scale; }
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
|
@ -213,6 +239,58 @@ protected:
|
|||
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
||||
};
|
||||
|
||||
class GLGizmoScale3D : public GLGizmoBase
|
||||
{
|
||||
static const float Offset;
|
||||
|
||||
mutable BoundingBoxf3 m_box;
|
||||
|
||||
float m_scale_x;
|
||||
float m_scale_y;
|
||||
float m_scale_z;
|
||||
|
||||
float m_starting_scale_x;
|
||||
float m_starting_scale_y;
|
||||
float m_starting_scale_z;
|
||||
|
||||
Pointf3 m_starting_drag_position;
|
||||
|
||||
public:
|
||||
GLGizmoScale3D();
|
||||
|
||||
float get_scale_x() const { return m_scale_x; }
|
||||
void set_scale_x(float scale) { m_starting_scale_x = scale; }
|
||||
|
||||
float get_scale_y() const { return m_scale_y; }
|
||||
void set_scale_y(float scale) { m_starting_scale_y = scale; }
|
||||
|
||||
float get_scale_z() const { return m_scale_z; }
|
||||
void set_scale_z(float scale) { m_starting_scale_z = scale; }
|
||||
|
||||
void set_scale(float scale)
|
||||
{
|
||||
m_starting_scale_x = scale;
|
||||
m_starting_scale_y = scale;
|
||||
m_starting_scale_z = scale;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_update(const Linef3& mouse_ray);
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
||||
|
||||
void render_box_x_faces() const;
|
||||
void render_box_y_faces() const;
|
||||
void render_box_z_faces() const;
|
||||
|
||||
void do_scale_x(const Linef3& mouse_ray);
|
||||
void do_scale_y(const Linef3& mouse_ray);
|
||||
void do_scale_z(const Linef3& mouse_ray);
|
||||
void do_scale_uniform(const Linef3& mouse_ray);
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
Loading…
Reference in a new issue