Fixed rendering of gizmo grabbers
This commit is contained in:
parent
e1d5d0804b
commit
8c560522a3
4 changed files with 28 additions and 12 deletions
|
@ -21,9 +21,6 @@ GLGizmoBase::Grabber::Grabber()
|
|||
, enabled(true)
|
||||
{
|
||||
color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
TriangleMesh mesh = make_cube(1., 1., 1.);
|
||||
mesh.translate(Vec3f(-0.5, -0.5, -0.5));
|
||||
cube.init_from(mesh);
|
||||
}
|
||||
|
||||
void GLGizmoBase::Grabber::render(bool hover, float size) const
|
||||
|
@ -53,6 +50,15 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const
|
|||
|
||||
void GLGizmoBase::Grabber::render(float size, const std::array<float, 4>& render_color, bool picking) const
|
||||
{
|
||||
if (! cube_initialized) {
|
||||
// This cannot be done in constructor, OpenGL is not yet
|
||||
// initialized at that point (on Linux at least).
|
||||
TriangleMesh mesh = make_cube(1., 1., 1.);
|
||||
mesh.translate(Vec3f(-0.5, -0.5, -0.5));
|
||||
const_cast<GLModel&>(cube).init_from(mesh);
|
||||
const_cast<bool&>(cube_initialized) = true;
|
||||
}
|
||||
|
||||
float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
|
||||
|
||||
GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_current_shader();
|
||||
|
|
|
@ -48,7 +48,6 @@ protected:
|
|||
static const float MinHalfSize;
|
||||
static const float DraggingScaleFactor;
|
||||
|
||||
GLModel cube;
|
||||
Vec3d center;
|
||||
Vec3d angles;
|
||||
std::array<float, 4> color;
|
||||
|
@ -65,6 +64,9 @@ protected:
|
|||
|
||||
private:
|
||||
void render(float size, const std::array<float, 4>& render_color, bool picking) const;
|
||||
|
||||
GLModel cube;
|
||||
bool cube_initialized = false;
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
|
@ -199,9 +199,12 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
|
|||
if (shader == nullptr)
|
||||
return;
|
||||
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1);
|
||||
shader->set_uniform("uniform_color", color);
|
||||
if (! picking) {
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1);
|
||||
shader->set_uniform("uniform_color", color);
|
||||
} else
|
||||
glsafe(::glColor4fv(color.data()));
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z()));
|
||||
|
@ -215,7 +218,8 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box
|
|||
m_vbo_cone.render();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
shader->stop_using();
|
||||
if (! picking)
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -336,9 +336,12 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
|||
if (shader == nullptr)
|
||||
return;
|
||||
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1);
|
||||
shader->set_uniform("uniform_color", color);
|
||||
if (! picking) {
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.1);
|
||||
shader->set_uniform("uniform_color", color);
|
||||
} else
|
||||
glsafe(::glColor4fv(color.data()));
|
||||
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z()));
|
||||
|
@ -357,7 +360,8 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick
|
|||
m_cone.render();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
shader->stop_using();
|
||||
if (! picking)
|
||||
shader->stop_using();
|
||||
}
|
||||
|
||||
void GLGizmoRotate::transform_to_local(const Selection& selection) const
|
||||
|
|
Loading…
Reference in a new issue