After merge fixes

This commit is contained in:
YuSanka 2022-03-14 14:09:10 +01:00
parent e5b10ae289
commit 01aa99f67f
2 changed files with 111 additions and 77 deletions

View File

@ -360,15 +360,27 @@ void GLGizmoCut3D::render_cut_plane()
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
/* const Vec3d diff = plane_center - m_old_center; #if ENABLE_GL_SHADERS_ATTRIBUTES
// Z changed when move with cut plane const Camera& camera = wxGetApp().plater()->get_camera();
// X and Y changed when move with cutted object const Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::assemble_transform(
bool is_changed = std::abs(diff.x()) > EPSILON || m_plane_center,
std::abs(diff.y()) > EPSILON || m_rotation_gizmo.get_rotation(),
std::abs(diff.z()) > EPSILON; Vec3d::Ones(),
m_old_center = plane_center; Vec3d::Ones()
*/ );
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
const Vec3d& angles = m_rotation_gizmo.get_rotation(); const Vec3d& angles = m_rotation_gizmo.get_rotation();
glsafe(::glPushMatrix());
glsafe(::glTranslated(m_plane_center.x(), m_plane_center.y(), m_plane_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));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (!m_plane.is_initialized()) {
m_plane.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 };
@ -376,33 +388,23 @@ void GLGizmoCut3D::render_cut_plane()
init_data.reserve_vertices(4); init_data.reserve_vertices(4);
init_data.reserve_indices(6); init_data.reserve_indices(6);
glsafe(::glPushMatrix());
glsafe(::glTranslated(m_plane_center.x(), m_plane_center.y(), m_plane_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));
if (!m_plane.is_initialized()) {
m_plane.reset();
// indices
init_data.add_triangle(0, 1, 2);
init_data.add_triangle(2, 3, 0);
// vertices // vertices
init_data.add_vertex(Vec3f(min_x, min_y, 0.0)); init_data.add_vertex(Vec3f(min_x, min_y, 0.0));
init_data.add_vertex(Vec3f(max_x, min_y, 0.0)); init_data.add_vertex(Vec3f(max_x, min_y, 0.0));
init_data.add_vertex(Vec3f(max_x, max_y, 0.0)); init_data.add_vertex(Vec3f(max_x, max_y, 0.0));
init_data.add_vertex(Vec3f(min_x, max_y, 0.0)); init_data.add_vertex(Vec3f(min_x, max_y, 0.0));
#if ENABLE_GL_SHADERS_ATTRIBUTES // indices
const Camera& camera = wxGetApp().plater()->get_camera(); init_data.add_triangle(0, 1, 2);
shader->set_uniform("view_model_matrix", camera.get_view_matrix()); init_data.add_triangle(2, 3, 0);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES m_plane.init_from(std::move(init_data));
}
m_plane.render(); m_plane.render();
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif //!ENABLE_GL_SHADERS_ATTRIBUTES
#else #else
// Draw the cutting plane // Draw the cutting plane
::glBegin(GL_QUADS); ::glBegin(GL_QUADS);
@ -437,11 +439,18 @@ void GLGizmoCut3D::render_cut_center_graber()
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
glsafe(::glLineWidth(m_hover_id == m_group_id ? 2.0f : 1.5f)); glsafe(::glLineWidth(m_hover_id == m_group_id ? 2.0f : 1.5f));
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
// if (!m_grabber_connection.is_initialized() || z_changed) #if ENABLE_GL_SHADERS_ATTRIBUTES
{ const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_grabber_connection.reset(); m_grabber_connection.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
@ -458,12 +467,13 @@ void GLGizmoCut3D::render_cut_center_graber()
init_data.add_line(0, 1); init_data.add_line(0, 1);
m_grabber_connection.init_from(std::move(init_data)); m_grabber_connection.init_from(std::move(init_data));
}
m_grabber_connection.render(); m_grabber_connection.render();
shader->stop_using(); shader->stop_using();
} }
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES #if ENABLE_GL_SHADERS_ATTRIBUTES
shader = wxGetApp().get_shader("gouraud_light_attr"); shader = wxGetApp().get_shader("gouraud_light_attr");
#else #else
@ -565,7 +575,7 @@ void GLGizmoCut3D::on_dragging(const UpdateData& data)
for (auto& connector : connectors) for (auto& connector : connectors)
connector.pos += shift; connector.pos += shift;
} }
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
else if (m_hover_id > m_group_id) else if (m_hover_id > m_group_id)
{ {
std::pair<Vec3f, Vec3f> pos_and_normal; std::pair<Vec3f, Vec3f> pos_and_normal;
@ -693,7 +703,7 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit)
revert_rotation = render_revert_button("rotation"); revert_rotation = render_revert_button("rotation");
for (Axis axis : {X, Y, Z}) for (Axis axis : {X, Y, Z})
render_rotation_input(axis); render_rotation_input(axis);
m_imgui->text(_L("°")); m_imgui->text(_L("°"));
} }
else { else {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
@ -792,27 +802,31 @@ void GLGizmoCut3D::render_connectors(bool picking)
{ {
const Selection& selection = m_parent.get_selection(); const Selection& selection = m_parent.get_selection();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat_attr") : wxGetApp().get_shader("gouraud_light_attr");
#else
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader == nullptr) if (shader == nullptr)
return; return;
shader->start_using(); shader->start_using();
ScopeGuard guard([shader]() { shader->stop_using(); }); ScopeGuard guard([shader]() { shader->stop_using(); });
#else #else
GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light");
if (shader) if (shader)
shader->start_using(); shader->start_using();
ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); ScopeGuard guard([shader]() { if (shader) shader->stop_using(); });
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin());
//const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
//const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift())); glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift()));
// glsafe(::glMultMatrixd(instance_matrix.data())); #endif // ENABLE_GL_SHADERS_ATTRIBUTES
ColorRGBA render_color; ColorRGBA render_color;
const CutConnectors& connectors = m_c->selection_info()->model_object()->cut_connectors; const CutConnectors& connectors = m_c->selection_info()->model_object()->cut_connectors;
@ -832,41 +846,44 @@ void GLGizmoCut3D::render_connectors(bool picking)
render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f); render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f);
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_connector_shape.set_color(render_color); m_connector_shape.set_color(render_color);
#else #else
const_cast<GLModel*>(&m_connector_shape)->set_color(-1, render_color); const_cast<GLModel*>(&m_connector_shape)->set_color(-1, render_color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. #if ENABLE_GL_SHADERS_ATTRIBUTES
const Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::assemble_transform(
Vec3d(connector.pos.x(), connector.pos.y(), connector.pos.z() - 0.5 * connector.height),
m_rotation_gizmo.get_rotation(),
Vec3d(connector.radius, connector.radius, connector.height),
Vec3d::Ones()
);
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
// glsafe(::glTranslatef(connector.pos.x() - m_plane_center.x(), connector.pos.y() - m_plane_center.y(), connector.pos.z() - m_plane_center.z()));
glsafe(::glTranslatef(connector.pos.x(), connector.pos.y(), connector.pos.z())); glsafe(::glTranslatef(connector.pos.x(), connector.pos.y(), connector.pos.z()));
// glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
if (vol->is_left_handed())
glFrontFace(GL_CW);
const Vec3d& angles = m_rotation_gizmo.get_rotation(); const Vec3d& angles = m_rotation_gizmo.get_rotation();
glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0)); 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.y()), 0.0, 1.0, 0.0));
glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0)); glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0));
// Matrices set, we can render the point mark now. glsafe(::glTranslated(0., 0., -0.5*connector.height));
/* Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-connector.normal).cast<double>());
Eigen::AngleAxisd aa(q);
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
*/ glsafe(::glTranslated(0., 0., -0.5*connector.height));
glsafe(::glScaled(connector.radius, connector.radius, connector.height)); glsafe(::glScaled(connector.radius, connector.radius, connector.height));
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_connector_shape.render(); m_connector_shape.render();
if (vol->is_left_handed()) #if !ENABLE_GL_SHADERS_ATTRIBUTES
glFrontFace(GL_CCW);
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif //!ENABLE_GL_SHADERS_ATTRIBUTES
} }
#if !ENABLE_GL_SHADERS_ATTRIBUTES
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif //!ENABLE_GL_SHADERS_ATTRIBUTES
} }
bool GLGizmoCut3D::can_perform_cut() const bool GLGizmoCut3D::can_perform_cut() const
@ -916,10 +933,12 @@ bool GLGizmoCut3D::unproject_on_cut_plane(const Vec2d& mouse_position, std::pair
if (!m_c->raycaster()->raycaster()) if (!m_c->raycaster()->raycaster())
return false; return false;
const float sla_shift = m_c->selection_info()->get_sla_shift();
const ModelObject* mo = m_c->selection_info()->model_object(); const ModelObject* mo = m_c->selection_info()->model_object();
const ModelInstance* mi = mo->instances[m_c->selection_info()->get_active_instance()]; const ModelInstance* mi = mo->instances[m_c->selection_info()->get_active_instance()];
const Transform3d instance_trafo = mi->get_transformation().get_matrix(); const Transform3d instance_trafo = sla_shift > 0.0 ?
const Transform3d instance_trafo_not_translate = mi->get_transformation().get_matrix(true); Geometry::assemble_transform(Vec3d(0.0, 0.0, sla_shift), Vec3d::Zero(), Vec3d::Ones(), Vec3d::Ones()) * mi->get_transformation().get_matrix() : mi->get_transformation().get_matrix();
const Camera& camera = wxGetApp().plater()->get_camera(); const Camera& camera = wxGetApp().plater()->get_camera();
int mesh_id = -1; int mesh_id = -1;

View File

@ -119,22 +119,32 @@ void MeshClipper::render_cut()
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void MeshClipper::render_contour(const ColorRGBA& color) void MeshClipper::render_contour(const ColorRGBA& color)
#else #else
void MeshClipper::render_contour() void MeshClipper::render_contour()
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
{ {
if (! m_triangles_valid) if (! m_triangles_valid)
recalculate_triangles(); recalculate_triangles();
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); GLShaderProgram* curr_shader = wxGetApp().get_current_shader();
if (curr_shader != nullptr) if (curr_shader != nullptr)
curr_shader->stop_using(); curr_shader->stop_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
GLShaderProgram* shader = wxGetApp().get_shader("flat_attr");
#else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
#if ENABLE_GL_SHADERS_ATTRIBUTES
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
m_model_expanded.set_color(color); m_model_expanded.set_color(color);
m_model_expanded.render(); m_model_expanded.render();
shader->stop_using(); shader->stop_using();
@ -145,7 +155,7 @@ void MeshClipper::render_contour()
#else #else
if (m_vertex_array_expanded.has_VBOs()) if (m_vertex_array_expanded.has_VBOs())
m_vertex_array_expanded.render(); m_vertex_array_expanded.render();
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
@ -232,13 +242,17 @@ void MeshClipper::recalculate_triangles()
tr.pretranslate(0.001 * m_plane.get_normal().normalized()); // to avoid z-fighting tr.pretranslate(0.001 * m_plane.get_normal().normalized()); // to avoid z-fighting
std::vector<Vec2f> triangles2d = m_fill_cut
? triangulate_expolygons_2f(expolys, m_trafo.get_matrix().matrix().determinant() < 0.)
: std::vector<Vec2f>();
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_model.reset(); m_model.reset();
GLModel::Geometry init_data; GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
init_data.reserve_vertices(m_triangles2d.size()); init_data.reserve_vertices(triangles2d.size());
init_data.reserve_indices(m_triangles2d.size()); init_data.reserve_indices(triangles2d.size());
// vertices + indices // vertices + indices
for (auto it = triangles2d.cbegin(); it != triangles2d.cend(); it = it + 3) { for (auto it = triangles2d.cbegin(); it != triangles2d.cend(); it = it + 3) {
@ -272,11 +286,11 @@ void MeshClipper::recalculate_triangles()
} }
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_model_expanded.reset(); m_model_expanded.reset();
init_data = GLModel::Geometry(); init_data = GLModel::Geometry();
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::index_type(triangles2d.size()) }; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
init_data.reserve_vertices(triangles2d.size()); init_data.reserve_vertices(triangles2d.size());
init_data.reserve_indices(triangles2d.size()); init_data.reserve_indices(triangles2d.size());
@ -286,10 +300,11 @@ void MeshClipper::recalculate_triangles()
init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 1)).x(), (*(it + 1)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>()); init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 1)).x(), (*(it + 1)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>());
init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 2)).x(), (*(it + 2)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>()); init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 2)).x(), (*(it + 2)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>());
const size_t idx = it - triangles2d.cbegin(); const size_t idx = it - triangles2d.cbegin();
if (init_data.format.index_type == GLModel::Geometry::EIndexType::USHORT) init_data.add_triangle((unsigned short)idx, (unsigned short)idx + 1, (unsigned short)idx + 2);
init_data.add_ushort_triangle((unsigned short)idx, (unsigned short)idx + 1, (unsigned short)idx + 2); //if (init_data./*format.*/index_type == GLModel::Geometry::EIndexType::USHORT)
else // init_data.add_ushort_triangle((unsigned short)idx, (unsigned short)idx + 1, (unsigned short)idx + 2);
init_data.add_uint_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2); //else
// init_data.add_uint_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2);
} }
if (!init_data.is_empty()) if (!init_data.is_empty())
@ -304,7 +319,7 @@ void MeshClipper::recalculate_triangles()
m_vertex_array_expanded.push_triangle(idx, idx+1, idx+2); m_vertex_array_expanded.push_triangle(idx, idx+1, idx+2);
} }
m_vertex_array_expanded.finalize_geometry(true); m_vertex_array_expanded.finalize_geometry(true);
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL