mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-29 01:43:13 +08:00
FIX: gizmo screen size
jira: STUDIO-10293 Change-Id: I711575c970c47fae31df030b6f6bf14447a5803b
This commit is contained in:
parent
69edcd530f
commit
4005d78f5d
@ -7119,10 +7119,8 @@ BoundingBoxf3 GLCanvas3D::_max_bounding_box(bool include_gizmos, bool include_be
|
||||
// A better solution would ask the gizmo manager for the bounding box of the current active gizmo, if any
|
||||
if (include_gizmos && m_gizmos.is_running())
|
||||
{
|
||||
BoundingBoxf3 sel_bb = m_selection.get_bounding_box();
|
||||
Vec3d sel_bb_center = sel_bb.center();
|
||||
Vec3d extend_by = sel_bb.max_size() * Vec3d::Ones();
|
||||
bb.merge(BoundingBoxf3(sel_bb_center - extend_by, sel_bb_center + extend_by));
|
||||
const auto& t_aabb = m_gizmos.get_bounding_box();
|
||||
bb.merge(t_aabb);
|
||||
}
|
||||
|
||||
bb.merge(include_bed_model ? m_bed.extended_bounding_box() : m_bed.build_volume().bounding_volume());
|
||||
|
@ -378,6 +378,79 @@ void GLGizmoAdvancedCut::reset_all()
|
||||
m_rotate_lower = false;
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoAdvancedCut::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
|
||||
// rotate aabb
|
||||
if (m_is_dragging) {
|
||||
auto t_rotate_aabb = GLGizmoRotate3D::get_bounding_box();
|
||||
if (t_rotate_aabb.defined) {
|
||||
t_aabb.merge(t_rotate_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const auto t_x_aabb = m_gizmos[X].get_bounding_box();
|
||||
t_aabb.merge(t_x_aabb);
|
||||
|
||||
const auto t_y_aabb = m_gizmos[Y].get_bounding_box();
|
||||
t_aabb.merge(t_y_aabb);
|
||||
|
||||
const auto t_z_aabb = m_gizmos[Z].get_bounding_box();
|
||||
t_aabb.merge(t_z_aabb);
|
||||
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
// end rotate aabb
|
||||
|
||||
bool is_render_z_grabber = true; // m_hover_id < 0 || m_hover_id == cube_z_move_id;
|
||||
bool is_render_x_grabber = m_cut_mode == CutMode::cutTongueAndGroove; // m_hover_id < 0 || m_hover_id == cube_x_move_id;
|
||||
// m_move_z_grabber aabb
|
||||
if (is_render_z_grabber) {
|
||||
const auto& z_grabber = m_move_z_grabber.get_cube();
|
||||
if (z_grabber.is_initialized()) {
|
||||
auto z_grabber_aabb = z_grabber.get_bounding_box();
|
||||
const auto& z_grabber_model_matrix = m_move_z_grabber.m_matrix;
|
||||
z_grabber_aabb = z_grabber_aabb.transformed(z_grabber_model_matrix);
|
||||
z_grabber_aabb.defined = true;
|
||||
t_aabb.merge(z_grabber_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
}
|
||||
// end m_move_z_grabber
|
||||
|
||||
// m_move_x_grabber aabb
|
||||
if (is_render_x_grabber) {
|
||||
const auto& x_grabber = m_move_x_grabber.get_cube();
|
||||
if (x_grabber.is_initialized()) {
|
||||
auto x_grabber_aabb = x_grabber.get_bounding_box();
|
||||
const auto& x_grabber_model_matrix = m_move_x_grabber.m_matrix;
|
||||
x_grabber_aabb = x_grabber_aabb.transformed(x_grabber_model_matrix);
|
||||
x_grabber_aabb.defined = true;
|
||||
t_aabb.merge(x_grabber_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
}
|
||||
// end m_move_x_grabber
|
||||
|
||||
// m_plane aabb
|
||||
if (!m_connectors_editing) {
|
||||
if (m_plane.is_initialized()) {
|
||||
auto t_plane_aabb = m_plane.get_bounding_box();
|
||||
const auto t_plane_model_matrix = Geometry::translation_transform(m_plane_center) * m_rotate_matrix;
|
||||
t_plane_aabb = t_plane_aabb.transformed(t_plane_model_matrix);
|
||||
t_plane_aabb.defined = true;
|
||||
t_aabb.merge(t_plane_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
}
|
||||
// end m_plane aabb
|
||||
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
bool GLGizmoAdvancedCut::on_init()
|
||||
{
|
||||
if (!GLGizmoRotate3D::on_init())
|
||||
@ -1160,6 +1233,34 @@ void GLGizmoAdvancedCut::render_cut_plane_and_grabbers()
|
||||
if (m_cut_mode == CutMode::cutTongueAndGroove) {
|
||||
cp_clr.a(cp_clr.a() - 0.1f);
|
||||
}
|
||||
|
||||
const float fullsize = get_fixed_grabber_size();
|
||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
Transform3d screen_scalling_matrix{ Transform3d::Identity() };
|
||||
const auto& t_zoom = camera.get_zoom();
|
||||
screen_scalling_matrix.data()[0 * 4 + 0] = 1.0f / t_zoom;
|
||||
screen_scalling_matrix.data()[1 * 4 + 1] = 1.0f / t_zoom;
|
||||
screen_scalling_matrix.data()[2 * 4 + 2] = 1.0f / t_zoom;
|
||||
|
||||
auto calculate_model_matrix = [&screen_scalling_matrix](const Vec3d& source, const Vec3d& target, Transform3d& model_matrix, float fullsize)->void {
|
||||
Vec3d the_vector = target - source;
|
||||
const auto scale = fullsize * the_vector.stableNorm();
|
||||
const Vec3d center = source + screen_scalling_matrix.matrix().block<3, 3>(0, 0) * 0.5f * scale * the_vector.normalized();
|
||||
Vec3d rotation_axis;
|
||||
double rotation_angle;
|
||||
Matrix3d rotation_matrix;
|
||||
Geometry::rotation_from_two_vectors(Vec3d(1.0f, 0.0f, 0.0f), the_vector, rotation_axis, rotation_angle, &rotation_matrix);
|
||||
Matrix4d final_rotation_matrix{ Matrix4d::Identity() };
|
||||
for (int iColumn = 0; iColumn < 3; ++iColumn) {
|
||||
for (int jRow = 0; jRow < 3; ++jRow) {
|
||||
final_rotation_matrix.data()[4 * iColumn + jRow] = rotation_matrix.data()[3 * iColumn + jRow];
|
||||
}
|
||||
}
|
||||
model_matrix = Geometry::translation_transform(center.cast<double>()).matrix()
|
||||
* final_rotation_matrix
|
||||
* Geometry::scale_transform({ scale, scale, scale }).matrix();
|
||||
};
|
||||
|
||||
render_glmodel(m_plane, cp_clr.get_data(), Geometry::translation_transform(m_plane_center) * m_rotate_matrix);
|
||||
|
||||
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
||||
@ -1172,27 +1273,40 @@ void GLGizmoAdvancedCut::render_cut_plane_and_grabbers()
|
||||
bool is_render_x_grabber = m_cut_mode == CutMode::cutTongueAndGroove; // m_hover_id < 0 || m_hover_id == cube_x_move_id;
|
||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
if (is_render_z_grabber) {
|
||||
|
||||
Transform3d model_matrix{ Transform3d::Identity() };
|
||||
calculate_model_matrix(m_plane_center, m_move_z_grabber.center, model_matrix, 0.3 * fullsize);
|
||||
model_matrix = model_matrix * screen_scalling_matrix;
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glMultMatrixd(model_matrix.data()));
|
||||
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f));
|
||||
glsafe(::glColor3f(1.0, 1.0, 0.0));
|
||||
glLineStipple(1, 0x0FFF);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
::glBegin(GL_LINES);
|
||||
::glVertex3dv(m_plane_center.data());
|
||||
::glVertex3dv(m_move_z_grabber.center.data());
|
||||
glsafe(::glLineStipple(1, 0x0FFF));
|
||||
glsafe(::glEnable(GL_LINE_STIPPLE));
|
||||
glsafe(::glBegin(GL_LINES));
|
||||
glsafe(::glVertex3f(-0.5f, 0.0f, 0.0f));
|
||||
glsafe(::glVertex3f(0.5f, 0.0f, 0.0f));
|
||||
glsafe(::glEnd());
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
glsafe(::glDisable(GL_LINE_STIPPLE));
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
m_move_x_grabber.center = m_plane_center + m_plane_x_direction * Offset;
|
||||
if (is_render_x_grabber) {
|
||||
Transform3d model_matrix{ Transform3d::Identity() };
|
||||
calculate_model_matrix(m_plane_center, m_move_x_grabber.center, model_matrix, 0.3 * fullsize);
|
||||
model_matrix = model_matrix * screen_scalling_matrix;
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glMultMatrixd(model_matrix.data()));
|
||||
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f));
|
||||
glsafe(::glColor3f(1.0, 1.0, 0.0));
|
||||
glLineStipple(1, 0x0FFF);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
::glBegin(GL_LINES);
|
||||
::glVertex3dv(m_plane_center.data());
|
||||
::glVertex3dv(m_move_x_grabber.center.data());
|
||||
glsafe(::glLineStipple(1, 0x0FFF));
|
||||
glsafe(::glEnable(GL_LINE_STIPPLE));
|
||||
glsafe(::glBegin(GL_LINES));
|
||||
glsafe(::glVertex3f(-0.5f, 0.0f, 0.0f));
|
||||
glsafe(::glVertex3f(0.5f, 0.0f, 0.0f));
|
||||
glsafe(::glEnd());
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
glsafe(::glDisable(GL_LINE_STIPPLE));
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
|
||||
bool hover = (m_hover_id == get_group_id());
|
||||
@ -1204,18 +1318,26 @@ void GLGizmoAdvancedCut::render_cut_plane_and_grabbers()
|
||||
|
||||
// BBS set to fixed size grabber
|
||||
// float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
|
||||
float fullsize = get_grabber_size();
|
||||
|
||||
GLModel &cube_z = m_move_z_grabber.get_cube();
|
||||
GLModel &cube_x = m_move_x_grabber.get_cube();
|
||||
if (is_render_z_grabber) {
|
||||
Transform3d cube_mat = Geometry::translation_transform(m_move_z_grabber.center) * m_rotate_matrix * Geometry::scale_transform(fullsize); //
|
||||
render_glmodel(cube_z, render_color, cube_mat);
|
||||
Vec3d t_z_dir = m_move_z_grabber.center - m_plane_center;
|
||||
const auto scale_z = screen_scalling_matrix.matrix().block<3, 3>(0, 0) * 0.3 * fullsize * t_z_dir.stableNorm();
|
||||
const Vec3d target_z = m_plane_center + scale_z * t_z_dir.normalized();
|
||||
Transform3d cube_mat_z = Geometry::translation_transform(target_z) * m_rotate_matrix * Geometry::scale_transform(fullsize); //
|
||||
m_move_z_grabber.m_matrix = cube_mat_z * screen_scalling_matrix;
|
||||
render_glmodel(cube_z, render_color, m_move_z_grabber.m_matrix);
|
||||
}
|
||||
|
||||
if (is_render_x_grabber) {
|
||||
Transform3d cube_mat = Geometry::translation_transform(m_move_x_grabber.center) * m_rotate_matrix * Geometry::scale_transform(fullsize); //
|
||||
render_glmodel(cube_x, render_color, cube_mat);
|
||||
GLModel& cube_x = m_move_x_grabber.get_cube();
|
||||
Vec3d t_x_dir = m_move_x_grabber.center - m_plane_center;
|
||||
const auto scale_x = screen_scalling_matrix.matrix().block<3, 3>(0, 0) * 0.3 * fullsize * t_x_dir.stableNorm();
|
||||
const Vec3d target_x = m_plane_center + scale_x * t_x_dir.normalized();
|
||||
Transform3d cube_mat_x = Geometry::translation_transform(target_x) * m_rotate_matrix * Geometry::scale_transform(fullsize); //
|
||||
m_move_x_grabber.m_matrix = cube_mat_x * screen_scalling_matrix;
|
||||
render_glmodel(cube_x, render_color, m_move_x_grabber.m_matrix);
|
||||
}
|
||||
// Should be placed at last, because GLGizmoRotate3D clears depth buffer
|
||||
GLGizmoRotate3D::set_center(m_plane_center);
|
||||
|
@ -222,6 +222,8 @@ public:
|
||||
|
||||
virtual bool apply_clipping_plane() { return m_connectors_editing; }
|
||||
|
||||
BoundingBoxf3 get_bounding_box() const override;
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_load(cereal::BinaryInputArchive &ar) override;
|
||||
|
@ -71,7 +71,6 @@ void GLGizmoBase::load_render_colors()
|
||||
|
||||
GLGizmoBase::Grabber::Grabber()
|
||||
: center(Vec3d::Zero())
|
||||
, angles(Vec3d::Zero())
|
||||
, dragging(false)
|
||||
, enabled(true)
|
||||
{
|
||||
@ -114,6 +113,11 @@ GLModel& GLGizmoBase::Grabber::get_cube()
|
||||
return cube;
|
||||
}
|
||||
|
||||
void GLGizmoBase::Grabber::set_model_matrix(const Transform3d& model_matrix)
|
||||
{
|
||||
m_matrix = model_matrix;
|
||||
}
|
||||
|
||||
void GLGizmoBase::Grabber::render(const std::array<float, 4>& render_color, bool picking) const
|
||||
{
|
||||
if (! cube_initialized) {
|
||||
@ -132,11 +136,7 @@ void GLGizmoBase::Grabber::render(const std::array<float, 4>& render_color, bool
|
||||
const_cast<GLModel*>(&cube)->set_color(-1, render_color);
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(center.x(), center.y(), center.z()));
|
||||
glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0));
|
||||
glsafe(::glRotated(Geometry::rad2deg(angles.y()), 0.0, 1.0, 0.0));
|
||||
glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0));
|
||||
glsafe(::glScaled(fullsize, fullsize, fullsize));
|
||||
glsafe(::glMultMatrixd(m_matrix.data()));
|
||||
cube.render();
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
@ -256,12 +256,16 @@ float GLGizmoBase::get_grabber_size()
|
||||
{
|
||||
float grabber_size = 8.0f;
|
||||
if (GLGizmoBase::INV_ZOOM > 0) {
|
||||
grabber_size = GLGizmoBase::Grabber::FixedGrabberSize * GLGizmoBase::INV_ZOOM;
|
||||
grabber_size = grabber_size * GLGizmoBase::Grabber::GrabberSizeFactor;
|
||||
grabber_size = get_fixed_grabber_size() * GLGizmoBase::INV_ZOOM;
|
||||
}
|
||||
return grabber_size;
|
||||
}
|
||||
|
||||
float GLGizmoBase::get_fixed_grabber_size()
|
||||
{
|
||||
return GLGizmoBase::Grabber::FixedGrabberSize * GLGizmoBase::Grabber::GrabberSizeFactor;
|
||||
}
|
||||
|
||||
GLGizmoBase::GLGizmoBase(GLCanvas3D &parent, const std::string &icon_filename, unsigned int sprite_id)
|
||||
: m_parent(parent)
|
||||
, m_group_id(-1)
|
||||
@ -558,6 +562,74 @@ void GLGizmoBase::do_stop_dragging(bool perform_mouse_cleanup)
|
||||
m_parent.refresh_camera_scene_box();
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoBase::get_cross_mask_aabb(const Transform3d& matrix, const Vec3f& target, bool is_single) const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
|
||||
BoundingBoxf3 t_cross_aabb;
|
||||
t_cross_aabb.min = Vec3d(-0.5f, 0.0f, 0.0f);
|
||||
t_cross_aabb.max = Vec3d(0.5f, 0.0f, 0.0f);
|
||||
t_cross_aabb.defined = true;
|
||||
Transform3d model_matrix{ Transform3d::Identity() };
|
||||
// x axis aabb
|
||||
model_matrix = get_corss_mask_model_matrix(ECrossMaskType::X, target, is_single);
|
||||
auto t_x_axis_aabb = t_cross_aabb.transformed(matrix * model_matrix);
|
||||
t_x_axis_aabb.defined = true;
|
||||
t_aabb.merge(t_x_axis_aabb);
|
||||
t_aabb.defined = true;
|
||||
// end x axis aabb
|
||||
|
||||
// y axis aabb
|
||||
model_matrix = get_corss_mask_model_matrix(ECrossMaskType::Y, target, is_single);
|
||||
auto t_y_axis_aabb = t_cross_aabb.transformed(matrix * model_matrix);
|
||||
t_y_axis_aabb.defined = true;
|
||||
t_aabb.merge(t_y_axis_aabb);
|
||||
t_aabb.defined = true;
|
||||
// end y axis aabb
|
||||
|
||||
// z axis aabb
|
||||
model_matrix = get_corss_mask_model_matrix(ECrossMaskType::Z, target, is_single);
|
||||
auto t_z_axis_aabb = t_cross_aabb.transformed(matrix * model_matrix);
|
||||
t_z_axis_aabb.defined = true;
|
||||
t_aabb.merge(t_z_axis_aabb);
|
||||
t_aabb.defined = true;
|
||||
// end z axis aabb
|
||||
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
Transform3d GLGizmoBase::get_corss_mask_model_matrix(ECrossMaskType type, const Vec3f& target, bool is_single) const
|
||||
{
|
||||
double half_length = 4.0;
|
||||
const auto center_x = is_single ? target + Vec3f(half_length * 0.5f, 0.0f, 0.0f) : target;
|
||||
const float scale = is_single ? half_length : 2.0f * half_length;
|
||||
Transform3d model_matrix{ Transform3d::Identity() };
|
||||
if (ECrossMaskType::X == type) {
|
||||
model_matrix.data()[3 * 4 + 0] = center_x.x();
|
||||
model_matrix.data()[3 * 4 + 1] = center_x.y();
|
||||
model_matrix.data()[3 * 4 + 2] = center_x.z();
|
||||
model_matrix.data()[0 * 4 + 0] = scale;
|
||||
model_matrix.data()[1 * 4 + 1] = 1.0f;
|
||||
model_matrix.data()[2 * 4 + 2] = 1.0f;
|
||||
}
|
||||
else if (ECrossMaskType::Y == type) {
|
||||
const auto center_y = is_single ? target + Vec3f(0.0f, half_length * 0.5f, 0.0f) : target;
|
||||
model_matrix = Geometry::translation_transform(center_y.cast<double>())
|
||||
* Geometry::rotation_transform({ 0.0f, 0.0f, 0.5 * PI })
|
||||
* Geometry::scale_transform({ scale, 1.0f, 1.0f });
|
||||
}
|
||||
|
||||
else if (ECrossMaskType::Z == type) {
|
||||
const auto center_z = is_single ? target + Vec3f(0.0f, 0.0f, half_length * 0.5f) : target;
|
||||
model_matrix = Geometry::translation_transform(center_z.cast<double>())
|
||||
* Geometry::rotation_transform({ 0.0f, -0.5 * PI, 0.0f })
|
||||
* Geometry::scale_transform({ scale, 1.0f, 1.0f });
|
||||
}
|
||||
|
||||
return model_matrix;
|
||||
}
|
||||
|
||||
void GLGizmoBase::render_input_window(float x, float y, float bottom_limit)
|
||||
{
|
||||
on_render_input_window(x, y, bottom_limit);
|
||||
@ -569,6 +641,13 @@ void GLGizmoBase::render_input_window(float x, float y, float bottom_limit)
|
||||
}
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoBase::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
void GLGizmoBase::render_glmodel(GLModel &model, const std::array<float, 4> &color, Transform3d view_model_matrix, bool for_picking, float emission_factor)
|
||||
{
|
||||
glPushMatrix();
|
||||
|
@ -71,11 +71,12 @@ public:
|
||||
static const float FixedRadiusSize;
|
||||
|
||||
Vec3d center;
|
||||
Vec3d angles;
|
||||
/*Vec3d angles;*/
|
||||
std::array<float, 4> color;
|
||||
std::array<float, 4> hover_color;
|
||||
bool enabled;
|
||||
bool dragging;
|
||||
Transform3d m_matrix{ Transform3d::Identity() };
|
||||
|
||||
Grabber();
|
||||
|
||||
@ -85,6 +86,7 @@ public:
|
||||
float get_half_size(float size) const;
|
||||
float get_dragging_half_size(float size) const;
|
||||
GLModel& get_cube();
|
||||
void set_model_matrix(const Transform3d& model_matrix);
|
||||
|
||||
private:
|
||||
void render(const std::array<float, 4>& render_color, bool picking) const;
|
||||
@ -174,6 +176,7 @@ protected:
|
||||
size_t &selection_idx, float label_width, float item_width);
|
||||
void render_cross_mark(const Vec3f& target,bool is_single =false);
|
||||
static float get_grabber_size();
|
||||
static float get_fixed_grabber_size();
|
||||
|
||||
public:
|
||||
GLGizmoBase(GLCanvas3D& parent,
|
||||
@ -241,6 +244,7 @@ public:
|
||||
/// </summary>
|
||||
virtual void data_changed(bool is_serializing){};
|
||||
int get_count() { return ++count; }
|
||||
virtual BoundingBoxf3 get_bounding_box() const;
|
||||
static void render_glmodel(GLModel &model, const std::array<float, 4> &color, Transform3d view_model_matrix, bool for_picking = false, float emission_factor = 0.0f);
|
||||
protected:
|
||||
float last_input_window_width = 0;
|
||||
@ -293,6 +297,17 @@ protected:
|
||||
if (value <= _min) { value = _min; }
|
||||
}
|
||||
|
||||
BoundingBoxf3 get_cross_mask_aabb(const Transform3d& matrix, const Vec3f& target, bool is_single = false) const;
|
||||
|
||||
private:
|
||||
enum class ECrossMaskType
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z
|
||||
};
|
||||
Transform3d get_corss_mask_model_matrix(ECrossMaskType type, const Vec3f& target, bool is_single = false) const;
|
||||
|
||||
private:
|
||||
// Flag for dirty visible state of Gizmo
|
||||
// When True then need new rendering
|
||||
|
@ -62,6 +62,64 @@ void GLGizmoMove3D::data_changed(bool is_serializing)
|
||||
change_cs_by_selection();
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoMove3D::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
|
||||
Selection& selection = m_parent.get_selection();
|
||||
// m_cone aabb
|
||||
if (m_cone.is_initialized()) {
|
||||
const auto& t_cone_aabb = m_cone.get_bounding_box();
|
||||
const auto& [box, box_trafo] = selection.get_bounding_box_in_current_reference_system();
|
||||
|
||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
Transform3d screen_scalling_matrix{ Transform3d::Identity() };
|
||||
const auto& t_zoom = camera.get_zoom();
|
||||
screen_scalling_matrix.data()[0 * 4 + 0] = 1.0f / t_zoom;
|
||||
screen_scalling_matrix.data()[1 * 4 + 1] = 1.0f / t_zoom;
|
||||
screen_scalling_matrix.data()[2 * 4 + 2] = 1.0f / t_zoom;
|
||||
auto model_matrix = box_trafo * screen_scalling_matrix;
|
||||
|
||||
double size = get_fixed_grabber_size() * 0.75;//0.75 for arrow show
|
||||
for (unsigned int i = 0; i < 3; ++i) {
|
||||
if (m_grabbers[i].enabled) {
|
||||
auto i_model_matrix = model_matrix * Geometry::assemble_transform(m_grabbers[i].center);
|
||||
|
||||
if (i == X)
|
||||
i_model_matrix = i_model_matrix * Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitY());
|
||||
else if (i == Y)
|
||||
i_model_matrix = i_model_matrix * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitX());
|
||||
i_model_matrix = i_model_matrix * Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 2.0 * size));
|
||||
|
||||
auto i_aabb = t_cone_aabb.transformed(i_model_matrix);
|
||||
i_aabb.defined = true;
|
||||
t_aabb.merge(i_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// end m_cone aabb
|
||||
|
||||
// m_cross_mark aabb
|
||||
if (m_object_manipulation->is_instance_coordinates()) {
|
||||
Geometry::Transformation cur_tran;
|
||||
if (auto mi = m_parent.get_selection().get_selected_single_intance()) {
|
||||
cur_tran = mi->get_transformation();
|
||||
}
|
||||
else {
|
||||
cur_tran = selection.get_first_volume()->get_instance_transformation();
|
||||
}
|
||||
|
||||
auto t_cross_mask_aabb = get_cross_mask_aabb(cur_tran.get_matrix(), Vec3f::Zero(), true);
|
||||
t_cross_mask_aabb.defined = true;
|
||||
t_aabb.merge(t_cross_mask_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
|
||||
// end m_cross_mark aabb
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
bool GLGizmoMove3D::on_init()
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
@ -137,7 +195,17 @@ void GLGizmoMove3D::on_render()
|
||||
m_object_manipulation->cs_center = box_trafo.translation();
|
||||
}
|
||||
m_orient_matrix = box_trafo;
|
||||
float space_size = 20.f *INV_ZOOM;
|
||||
|
||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
Transform3d screen_scalling_matrix{ Transform3d::Identity() };
|
||||
const auto& t_zoom = camera.get_zoom();
|
||||
screen_scalling_matrix.data()[0 * 4 + 0] = 1.0f / t_zoom;
|
||||
screen_scalling_matrix.data()[1 * 4 + 1] = 1.0f / t_zoom;
|
||||
screen_scalling_matrix.data()[2 * 4 + 2] = 1.0f / t_zoom;
|
||||
m_orient_matrix = m_orient_matrix * screen_scalling_matrix;
|
||||
|
||||
float space_size = 100.f;
|
||||
|
||||
space_size *= GLGizmoBase::Grabber::GrabberSizeFactor;
|
||||
#if ENABLE_FIXED_GRABBER
|
||||
// x axis
|
||||
@ -263,7 +331,7 @@ double GLGizmoMove3D::calc_projection(const UpdateData& data) const
|
||||
|
||||
void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking) const
|
||||
{
|
||||
double size = get_grabber_size() * 0.75;//0.75 for arrow show
|
||||
double size = get_fixed_grabber_size() * 0.75;//0.75 for arrow show
|
||||
|
||||
std::array<float, 4> color = m_grabbers[axis].color;
|
||||
if (!picking && m_hover_id != -1) {
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
|
||||
std::string get_tooltip() const override;
|
||||
void data_changed(bool is_serializing) override;
|
||||
BoundingBoxf3 get_bounding_box() const override;
|
||||
|
||||
protected:
|
||||
virtual bool on_init() override;
|
||||
|
@ -16,7 +16,7 @@ namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
|
||||
const float GLGizmoRotate::Offset = 5.0f;
|
||||
const float GLGizmoRotate::Offset = 100.0f;
|
||||
const unsigned int GLGizmoRotate::CircleResolution = 64;
|
||||
const unsigned int GLGizmoRotate::AngleResolution = 64;
|
||||
const unsigned int GLGizmoRotate::ScaleStepsCount = 72;
|
||||
@ -130,10 +130,16 @@ void GLGizmoRotate::on_render()
|
||||
init_data_from_selection(selection);
|
||||
}
|
||||
|
||||
m_base_model_matrix = calculate_base_model_matrix();// transform_to_local(selection)* scalling_matrix;
|
||||
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
transform_to_local(selection);
|
||||
|
||||
Transform3d redius_scale_matrix;
|
||||
Geometry::scale_transform(redius_scale_matrix, { m_radius, m_radius, m_radius });
|
||||
Transform3d circle_model_matrix = m_base_model_matrix * redius_scale_matrix;
|
||||
glsafe(::glMultMatrixd(circle_model_matrix.data()));
|
||||
|
||||
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
|
||||
glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data()));
|
||||
@ -151,10 +157,16 @@ void GLGizmoRotate::on_render()
|
||||
if (m_hover_id != -1)
|
||||
render_angle();
|
||||
|
||||
render_grabber(m_bounding_box);
|
||||
render_grabber_extension(m_bounding_box, false);
|
||||
glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data()));
|
||||
|
||||
glsafe(::glBegin(GL_LINES));
|
||||
glsafe(::glVertex3f(0.0f, 0.0f, 0.0f));
|
||||
glsafe(::glVertex3f(::cos(m_angle) * (1.0 + (double)GrabberOffset), ::sin(m_angle) * (1.0 + (double)GrabberOffset), 0.0f));
|
||||
glsafe(::glEnd());
|
||||
|
||||
glsafe(::glPopMatrix());
|
||||
render_grabber(m_bounding_box);
|
||||
render_grabber_extension(m_bounding_box, false);
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_render_for_picking()
|
||||
@ -165,8 +177,6 @@ void GLGizmoRotate::on_render_for_picking()
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
|
||||
transform_to_local(selection);
|
||||
|
||||
const BoundingBoxf3& box = selection.get_bounding_box();
|
||||
render_grabbers_for_picking(box);
|
||||
render_grabber_extension(box, true);
|
||||
@ -212,8 +222,8 @@ void GLGizmoRotate::render_circle() const
|
||||
for (unsigned int i = 0; i < ScaleStepsCount; ++i)
|
||||
{
|
||||
float angle = (float)i * ScaleStepRad;
|
||||
float x = ::cos(angle) * m_radius;
|
||||
float y = ::sin(angle) * m_radius;
|
||||
float x = ::cos(angle) * 1.0f;
|
||||
float y = ::sin(angle) * 1.0f;
|
||||
float z = 0.0f;
|
||||
::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z);
|
||||
}
|
||||
@ -223,7 +233,7 @@ void GLGizmoRotate::render_circle() const
|
||||
void GLGizmoRotate::render_scale() const
|
||||
{
|
||||
float out_radius_long = m_snap_fine_out_radius;
|
||||
float out_radius_short = m_radius * (1.0f + 0.5f * ScaleLongTooth);
|
||||
float out_radius_short = 1.0f * (1.0f + 0.5f * ScaleLongTooth);
|
||||
|
||||
::glBegin(GL_LINES);
|
||||
for (unsigned int i = 0; i < ScaleStepsCount; ++i)
|
||||
@ -231,8 +241,8 @@ void GLGizmoRotate::render_scale() const
|
||||
float angle = (float)i * ScaleStepRad;
|
||||
float cosa = ::cos(angle);
|
||||
float sina = ::sin(angle);
|
||||
float in_x = cosa * m_radius;
|
||||
float in_y = sina * m_radius;
|
||||
float in_x = cosa * 1.0f;
|
||||
float in_y = sina * 1.0f;
|
||||
float in_z = 0.0f;
|
||||
float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short;
|
||||
float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short;
|
||||
@ -247,7 +257,7 @@ void GLGizmoRotate::render_snap_radii() const
|
||||
{
|
||||
float step = 2.0f * (float)PI / (float)SnapRegionsCount;
|
||||
|
||||
float in_radius = m_radius / 3.0f;
|
||||
float in_radius = 1.0f / 3.0f;
|
||||
float out_radius = 2.0f * in_radius;
|
||||
|
||||
::glBegin(GL_LINES);
|
||||
@ -272,14 +282,14 @@ void GLGizmoRotate::render_reference_radius() const
|
||||
{
|
||||
::glBegin(GL_LINES);
|
||||
::glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
::glVertex3f((GLfloat)(m_radius * (1.0f + GrabberOffset)), 0.0f, 0.0f);
|
||||
::glVertex3f((GLfloat)(1.0f * (1.0f + GrabberOffset)), 0.0f, 0.0f);
|
||||
glsafe(::glEnd());
|
||||
}
|
||||
|
||||
void GLGizmoRotate::render_angle() const
|
||||
{
|
||||
float step_angle = (float)m_angle / AngleResolution;
|
||||
float ex_radius = m_radius * (1.0f + GrabberOffset);
|
||||
float ex_radius = 1.0f * (1.0f + GrabberOffset);
|
||||
|
||||
::glBegin(GL_LINE_STRIP);
|
||||
for (unsigned int i = 0; i <= AngleResolution; ++i)
|
||||
@ -297,16 +307,12 @@ void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const
|
||||
{
|
||||
double grabber_radius = (double)m_radius * (1.0 + (double)GrabberOffset);
|
||||
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
|
||||
m_grabbers[0].angles(2) = m_angle;
|
||||
m_grabbers[0].color = AXES_COLOR[m_axis];
|
||||
m_grabbers[0].hover_color = AXES_HOVER_COLOR[m_axis];
|
||||
|
||||
glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data()));
|
||||
|
||||
::glBegin(GL_LINES);
|
||||
::glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
::glVertex3dv(m_grabbers[0].center.data());
|
||||
glsafe(::glEnd());
|
||||
const auto t_angle = Vec3d(0.0f, 0.0f, m_angle);
|
||||
const auto t_fullsize = get_fixed_grabber_size();
|
||||
m_grabbers.front().m_matrix = m_base_model_matrix * Geometry::assemble_transform(m_grabbers.front().center, t_angle, t_fullsize * Vec3d::Ones());
|
||||
|
||||
m_grabbers[0].color = m_highlight_color;
|
||||
render_grabbers(box);
|
||||
@ -314,7 +320,7 @@ void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const
|
||||
|
||||
void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool picking) const
|
||||
{
|
||||
double size = get_grabber_size() * 0.75;//0.75 for arrow show
|
||||
double size = get_fixed_grabber_size() * 0.75;//0.75 for arrow show
|
||||
|
||||
std::array<float, 4> color = m_grabbers[0].color;
|
||||
if (!picking && m_hover_id != -1) {
|
||||
@ -334,20 +340,20 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
||||
shader->set_uniform("emission_factor", 0.1f);
|
||||
}
|
||||
|
||||
const Vec3d& center = m_grabbers.front().center;
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z()));
|
||||
glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0));
|
||||
glsafe(::glRotated(90.0, 1.0, 0.0, 0.0));
|
||||
glsafe(::glTranslated(0.0, 0.0, 1.5 * size));
|
||||
glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size));
|
||||
Transform3d model_matrix = m_base_model_matrix
|
||||
* Geometry::assemble_transform(center, Vec3d(0.5 * PI, 0.0, m_angle))
|
||||
* Geometry::assemble_transform(1.5 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size));
|
||||
glsafe(::glMultMatrixd(model_matrix.data()));
|
||||
m_cone.render();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
model_matrix = m_base_model_matrix *
|
||||
Geometry::assemble_transform(center, Vec3d(-0.5 * PI, 0.0, m_angle)) *
|
||||
Geometry::assemble_transform(1.5 * size * Vec3d::UnitZ(), Vec3d::Zero(), Vec3d(0.75 * size, 0.75 * size, 3.0 * size));
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z()));
|
||||
glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0));
|
||||
glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0));
|
||||
glsafe(::glTranslated(0.0, 0.0, 1.5 * size));
|
||||
glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size));
|
||||
glsafe(::glMultMatrixd(model_matrix.data()));
|
||||
m_cone.render();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
@ -355,35 +361,54 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
void GLGizmoRotate::transform_to_local(const Selection &selection) const
|
||||
Transform3d GLGizmoRotate::calculate_base_model_matrix() const
|
||||
{
|
||||
glsafe(::glTranslated(m_center(0), m_center(1), m_center(2)));
|
||||
const Selection& selection = m_parent.get_selection();
|
||||
/*if (m_hover_id != 0 && !m_grabbers[0].dragging) {
|
||||
init_data_from_selection(selection);
|
||||
}*/
|
||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
Transform3d scalling_matrix{ Transform3d::Identity() };
|
||||
const auto& t_zoom = camera.get_zoom();
|
||||
scalling_matrix.data()[0 * 4 + 0] = 1.0f / t_zoom;
|
||||
scalling_matrix.data()[1 * 4 + 1] = 1.0f / t_zoom;
|
||||
scalling_matrix.data()[2 * 4 + 2] = 1.0f / t_zoom;
|
||||
return transform_to_local(selection) * scalling_matrix;
|
||||
}
|
||||
|
||||
if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes() || m_force_local_coordinate) {
|
||||
glsafe(::glMultMatrixd(Geometry::Transformation(m_orient_matrix).get_matrix_no_offset().data()));
|
||||
}
|
||||
Transform3d GLGizmoRotate::calculate_circle_model_matrix() const
|
||||
{
|
||||
Transform3d redius_scale_matrix;
|
||||
Geometry::scale_transform(redius_scale_matrix, { m_radius, m_radius, m_radius });
|
||||
const auto t_base_model_matrix = calculate_base_model_matrix();
|
||||
return t_base_model_matrix * redius_scale_matrix;
|
||||
}
|
||||
|
||||
Transform3d GLGizmoRotate::transform_to_local(const Selection &selection) const
|
||||
{
|
||||
Transform3d ret;
|
||||
switch (m_axis)
|
||||
{
|
||||
case X:
|
||||
{
|
||||
glsafe(::glRotatef(90.0f, 0.0f, 1.0f, 0.0f));
|
||||
glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f));
|
||||
ret = Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitY()) * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ());
|
||||
break;
|
||||
}
|
||||
case Y:
|
||||
{
|
||||
glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f));
|
||||
glsafe(::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f));
|
||||
ret = Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ()) * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitY());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case Z:
|
||||
{
|
||||
// no rotation
|
||||
ret = Transform3d::Identity();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes())
|
||||
ret = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true) * ret;
|
||||
return m_orient_matrix * ret;
|
||||
}
|
||||
|
||||
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const
|
||||
@ -430,16 +455,66 @@ void GLGizmoRotate::init_data_from_selection(const Selection &selection) {
|
||||
m_bounding_box = box;
|
||||
const std::pair<Vec3d, double> sphere = selection.get_bounding_sphere();
|
||||
m_center = sphere.first;
|
||||
m_radius = Offset + sphere.second;
|
||||
m_radius = Offset;// +sphere.second;
|
||||
m_orient_matrix = box_trafo;
|
||||
m_orient_matrix.translation() = m_center;
|
||||
m_snap_coarse_in_radius = m_radius / 3.0f;
|
||||
m_snap_coarse_in_radius = 1.0f / 3.0f;
|
||||
m_snap_coarse_out_radius = 2.0f * m_snap_coarse_in_radius;
|
||||
m_snap_fine_in_radius = m_radius;
|
||||
m_snap_fine_out_radius = m_snap_fine_in_radius + m_radius * ScaleLongTooth;
|
||||
m_snap_fine_in_radius = 1.0f;
|
||||
m_snap_fine_out_radius = m_snap_fine_in_radius + 1.0f * ScaleLongTooth;
|
||||
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoRotate::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
|
||||
// m_circle aabb
|
||||
Transform3d t_circle_model_matrix = calculate_circle_model_matrix();
|
||||
BoundingBoxf3 t_circle_aabb;
|
||||
t_circle_aabb.min = Vec3d(-1.0f, -1.0f, 0.0f);
|
||||
t_circle_aabb.max = Vec3d(1.0f, 1.0f, 0.0f);
|
||||
t_circle_aabb.defined = true;
|
||||
t_circle_aabb.defined = true;
|
||||
t_circle_aabb = t_circle_aabb.transformed(t_circle_model_matrix);
|
||||
t_circle_aabb.defined = true;
|
||||
t_aabb.merge(t_circle_aabb);
|
||||
t_aabb.defined = true;
|
||||
// end m_circle aabb
|
||||
|
||||
// m_grabber_connection aabb
|
||||
BoundingBoxf3 t_grabber_connection_aabb;
|
||||
t_grabber_connection_aabb.merge(Vec3d(0.0f, 0.0f, 0.0f));
|
||||
t_grabber_connection_aabb.merge(Vec3d(::cos(m_angle) * (1.0 + (double)GrabberOffset), ::sin(m_angle) * (1.0 + (double)GrabberOffset), 0.0f));
|
||||
t_grabber_connection_aabb.defined = true;
|
||||
t_grabber_connection_aabb = t_grabber_connection_aabb.transformed(t_circle_model_matrix);
|
||||
t_grabber_connection_aabb.defined = true;
|
||||
t_aabb.merge(t_grabber_connection_aabb);
|
||||
t_aabb.defined = true;
|
||||
|
||||
|
||||
// m_grabbers aabb
|
||||
if (m_grabbers.front().get_cube().is_initialized()) {
|
||||
auto t_grabbers_aabb = m_grabbers.front().get_cube().get_bounding_box();
|
||||
t_grabbers_aabb = t_grabbers_aabb.transformed(m_grabbers.front().m_matrix);
|
||||
t_grabbers_aabb.defined = true;
|
||||
t_aabb.merge(t_grabbers_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
// end m_grabbers aabb
|
||||
|
||||
// m_cone aabb
|
||||
if (m_cone.is_initialized()) {
|
||||
auto t_cone_aabb = m_cone.get_bounding_box();
|
||||
t_cone_aabb = t_cone_aabb.transformed(m_grabbers.front().m_matrix);
|
||||
t_cone_aabb.defined = true;
|
||||
t_aabb.merge(t_cone_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
//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)
|
||||
@ -457,6 +532,34 @@ GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_fil
|
||||
load_rotoptimize_state();
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoRotate3D::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
|
||||
if (m_hover_id == -1 || m_hover_id == 0)
|
||||
{
|
||||
const auto t_x_aabb = m_gizmos[X].get_bounding_box();
|
||||
t_aabb.merge(t_x_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
|
||||
if (m_hover_id == -1 || m_hover_id == 1)
|
||||
{
|
||||
const auto t_y_aabb = m_gizmos[Y].get_bounding_box();
|
||||
t_aabb.merge(t_y_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
|
||||
if (m_hover_id == -1 || m_hover_id == 2)
|
||||
{
|
||||
const auto t_z_aabb = m_gizmos[Z].get_bounding_box();
|
||||
t_aabb.merge(t_z_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
bool GLGizmoRotate3D::on_init()
|
||||
{
|
||||
for (GLGizmoRotate& g : m_gizmos) {
|
||||
|
@ -47,6 +47,7 @@ private:
|
||||
|
||||
// emboss need to draw rotation gizmo in local coordinate systems
|
||||
bool m_force_local_coordinate{false};
|
||||
Transform3d m_base_model_matrix{ Transform3d::Identity() };
|
||||
public:
|
||||
GLGizmoRotate(GLCanvas3D& parent, Axis axis);
|
||||
GLGizmoRotate(const GLGizmoRotate& other);
|
||||
@ -61,6 +62,8 @@ public:
|
||||
void set_force_local_coordinate(bool use) { m_force_local_coordinate = use; }
|
||||
void init_data_from_selection(const Selection &selection);
|
||||
|
||||
BoundingBoxf3 get_bounding_box() const override;
|
||||
|
||||
protected:
|
||||
bool on_init() override;
|
||||
std::string on_get_name() const override { return ""; }
|
||||
@ -77,8 +80,9 @@ private:
|
||||
void render_angle() const;
|
||||
void render_grabber(const BoundingBoxf3& box) const;
|
||||
void render_grabber_extension(const BoundingBoxf3& box, bool picking) const;
|
||||
|
||||
void transform_to_local(const Selection& selection) const;
|
||||
Transform3d calculate_base_model_matrix() const;
|
||||
Transform3d calculate_circle_model_matrix() const;
|
||||
Transform3d transform_to_local(const Selection& selection) const;
|
||||
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
|
||||
Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const;
|
||||
};
|
||||
@ -117,6 +121,8 @@ public:
|
||||
m_gizmos[Z].set_center(point);
|
||||
}
|
||||
|
||||
BoundingBoxf3 get_bounding_box() const override;
|
||||
|
||||
protected:
|
||||
bool on_init() override;
|
||||
std::string on_get_name() const override;
|
||||
|
@ -606,6 +606,7 @@ void GLGizmoSVG::on_render()
|
||||
m_move_grabber.center = tran.get_offset();
|
||||
Transform3d rotate_matrix = tran.get_rotation_matrix();
|
||||
Transform3d cube_mat = Geometry::translation_transform(m_move_grabber.center) * rotate_matrix * Geometry::scale_transform(fullsize);
|
||||
m_move_grabber.set_model_matrix(cube_mat);
|
||||
render_glmodel(m_move_grabber.get_cube(), render_color, cube_mat);
|
||||
}
|
||||
#ifdef DEBUG_SVG
|
||||
@ -2188,6 +2189,27 @@ bool GLGizmoSVG::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_positi
|
||||
return true;
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoSVG::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
|
||||
// m_rotate_gizmo aabb
|
||||
bool is_rotate_by_grabbers = m_dragging;
|
||||
bool is_surface_dragging = m_surface_drag.has_value();
|
||||
bool is_parent_dragging = m_parent.is_mouse_dragging();
|
||||
if (is_rotate_by_grabbers || (!is_surface_dragging && !is_parent_dragging)) {
|
||||
if (m_hover_id != c_move_cube_id || !m_dragging) {
|
||||
auto t_totate_gizmo_aabb = m_rotate_gizmo.get_bounding_box();
|
||||
t_aabb.merge(t_totate_gizmo_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
}
|
||||
// end m_rotate_gizmo aabb
|
||||
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
void GLGizmoSVG::update_single_mesh_pick(GLVolume *v)
|
||||
{
|
||||
if (m_mesh_raycaster_map.find(v) != m_mesh_raycaster_map.end()) {
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
|
||||
void update_single_mesh_pick(GLVolume *v);
|
||||
bool gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_position, bool shift_down, bool alt_down, bool control_down);
|
||||
BoundingBoxf3 get_bounding_box() const override;
|
||||
|
||||
protected:
|
||||
bool on_is_selectable() const override { return false; }
|
||||
|
@ -84,6 +84,31 @@ void GLGizmoScale3D::enable_ununiversal_scale(bool enable)
|
||||
m_grabbers[i].enabled = enable;
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmoScale3D::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
|
||||
for (unsigned int i = 0; i < m_grabbers.size(); ++i) {
|
||||
if (!m_grabbers[i].enabled) {
|
||||
continue;
|
||||
}
|
||||
const auto& t_grabber_model = m_grabbers[i].get_cube();
|
||||
if (!t_grabber_model.is_initialized()) {
|
||||
continue;
|
||||
}
|
||||
auto t_grabber_aabb = t_grabber_model.get_bounding_box();
|
||||
const auto& t_grabber_model_matrix = m_grabbers[i].m_matrix;
|
||||
t_grabber_aabb = t_grabber_aabb.transformed(t_grabber_model_matrix);
|
||||
t_grabber_aabb.defined = true;
|
||||
|
||||
t_aabb.merge(t_grabber_aabb);
|
||||
t_aabb.defined = true;
|
||||
}
|
||||
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
bool GLGizmoScale3D::on_init()
|
||||
{
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@ -217,14 +242,19 @@ void GLGizmoScale3D::update_grabbers_data()
|
||||
m_grabbers[8].color = (ctrl_down && m_hover_id == 6) ? CONSTRAINED_COLOR : GRABBER_UNIFORM_COL;
|
||||
m_grabbers[9].center = Vec3d(-box_half_size.x(), box_half_size.y(), -box_half_size.z());
|
||||
m_grabbers[9].color = (ctrl_down && m_hover_id == 7) ? CONSTRAINED_COLOR : GRABBER_UNIFORM_COL;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
//m_grabbers[i].color = AXES_COLOR[i / 2];
|
||||
|
||||
Transform3d t_model_matrix{ Transform3d::Identity() };
|
||||
const auto t_fullsize = get_grabber_size();
|
||||
for (int i = 0; i < m_grabbers.size(); ++i) {
|
||||
if (i < 6) {
|
||||
m_grabbers[i].hover_color = AXES_HOVER_COLOR[i / 2];
|
||||
}
|
||||
for (int i = 6; i < 10; ++i) {
|
||||
//m_grabbers[i].color = GRABBER_UNIFORM_COL;
|
||||
else {
|
||||
m_grabbers[i].hover_color = GRABBER_UNIFORM_HOVER_COL;
|
||||
}
|
||||
t_model_matrix = m_grabbers_tran.get_matrix() * Geometry::assemble_transform(m_grabbers[i].center, Vec3d(0.0f, 0.0f, 0.0f), t_fullsize * Vec3d::Ones());
|
||||
m_grabbers[i].set_model_matrix(t_model_matrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -269,19 +299,15 @@ void GLGizmoScale3D::on_render()
|
||||
glsafe(::glColor4fv(m_grabbers[0].color.data()));
|
||||
render_grabbers_connection(7, 8);
|
||||
render_grabbers_connection(9, 6);
|
||||
|
||||
glsafe(::glPopMatrix());
|
||||
// draw grabbers
|
||||
render_grabbers();
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::on_render_for_picking()
|
||||
{
|
||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glMultMatrixd(m_grabbers_tran.get_matrix().data()));
|
||||
render_grabbers_for_picking(m_parent.get_selection().get_bounding_box());
|
||||
glsafe(::glPopMatrix());
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
std::string get_tooltip() const override;
|
||||
void data_changed(bool is_serializing) override;
|
||||
void enable_ununiversal_scale(bool enable);
|
||||
BoundingBoxf3 get_bounding_box() const override;
|
||||
protected:
|
||||
virtual bool on_init() override;
|
||||
virtual std::string on_get_name() const override;
|
||||
|
@ -730,6 +730,7 @@ void GLGizmoText::on_render()
|
||||
m_move_grabber.center = tran.get_offset();
|
||||
Transform3d rotate_matrix = tran.get_rotation_matrix();
|
||||
Transform3d cube_mat = Geometry::translation_transform(m_move_grabber.center) * rotate_matrix * Geometry::scale_transform(fullsize);
|
||||
m_move_grabber.set_model_matrix(cube_mat);
|
||||
render_glmodel(m_move_grabber.get_cube(), render_color, cube_mat);
|
||||
}
|
||||
|
||||
|
@ -1564,6 +1564,18 @@ void GLGizmosManager::update_after_undo_redo(const UndoRedo::Snapshot& snapshot)
|
||||
dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->reslice_SLA_supports(true);
|
||||
}
|
||||
|
||||
BoundingBoxf3 GLGizmosManager::get_bounding_box() const
|
||||
{
|
||||
BoundingBoxf3 t_aabb;
|
||||
t_aabb.reset();
|
||||
if (!m_enabled || m_current == Undefined)
|
||||
return t_aabb;
|
||||
|
||||
t_aabb = m_gizmos[m_current]->get_bounding_box();
|
||||
|
||||
return t_aabb;
|
||||
}
|
||||
|
||||
void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border) const
|
||||
{
|
||||
unsigned int tex_id = m_background_texture.texture.get_id();
|
||||
|
@ -341,7 +341,7 @@ public:
|
||||
float get_scaled_total_width() const;
|
||||
GizmoObjectManipulation& get_object_manipulation() { return m_object_manipulation; }
|
||||
bool get_uniform_scaling() const { return m_object_manipulation.get_uniform_scaling();}
|
||||
|
||||
BoundingBoxf3 get_bounding_box() const;
|
||||
private:
|
||||
void render_background(float left, float top, float right, float bottom, float border) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user