mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 11:45:56 +08:00
Center of gravity and tool marker may both be rendered with fixed screen size and a scaling factor
This commit is contained in:
parent
85d0e9dbd5
commit
ce8da7eccf
@ -224,7 +224,7 @@ void GCodeViewer::COG::render()
|
||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
|
||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
Transform3d model_matrix = Geometry::translation_transform(cog());
|
||||
Transform3d model_matrix = Geometry::translation_transform(cog()) * Geometry::scale_transform(m_scale_factor);
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
if (fixed_screen_size) {
|
||||
@ -334,13 +334,6 @@ void GCodeViewer::SequentialView::Marker::init()
|
||||
m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f });
|
||||
}
|
||||
|
||||
void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& position)
|
||||
{
|
||||
m_world_position = position;
|
||||
m_world_transform = (Geometry::translation_transform((position + m_model_z_offset * Vec3f::UnitZ()).cast<double>()) *
|
||||
Geometry::translation_transform(m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })).cast<float>();
|
||||
}
|
||||
|
||||
void GCodeViewer::SequentialView::Marker::render()
|
||||
{
|
||||
if (!m_visible)
|
||||
@ -357,7 +350,12 @@ void GCodeViewer::SequentialView::Marker::render()
|
||||
shader->set_uniform("emission_factor", 0.0f);
|
||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
const Transform3d& view_matrix = camera.get_view_matrix();
|
||||
const Transform3d model_matrix = m_world_transform.cast<double>();
|
||||
float scale_factor = m_scale_factor;
|
||||
if (m_fixed_screen_size)
|
||||
scale_factor *= 10.0f * camera.get_inv_zoom();
|
||||
const Transform3d model_matrix = (Geometry::translation_transform((m_world_position + m_model_z_offset * Vec3f::UnitZ()).cast<double>()) *
|
||||
Geometry::translation_transform(scale_factor * m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })) *
|
||||
Geometry::scale_transform(scale_factor);
|
||||
shader->set_uniform("view_model_matrix", view_matrix * model_matrix);
|
||||
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
|
||||
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||
@ -1230,6 +1228,7 @@ void GCodeViewer::render()
|
||||
std::memcpy(converted_tool_marker_position.data(), m_sequential_view.current_position.data(), 3 * sizeof(float));
|
||||
|
||||
m_new_viewer.set_cog_marker_scale_factor(m_cog_marker_fixed_screen_size ? 10.0f * m_cog_marker_size * camera.get_inv_zoom() : m_cog_marker_size);
|
||||
m_new_viewer.enable_tool_marker(m_sequential_view.current.last != m_sequential_view.endpoints.last);
|
||||
m_new_viewer.set_tool_marker_position(converted_tool_marker_position);
|
||||
m_new_viewer.set_tool_marker_scale_factor(m_tool_marker_fixed_screen_size ? 10.0f * m_tool_marker_size * camera.get_inv_zoom() : m_tool_marker_size);
|
||||
#endif // !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
|
@ -404,6 +404,7 @@ class GCodeViewer
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#endif // ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
float m_scale_factor{ 1.0f };
|
||||
double m_total_mass{ 0.0 };
|
||||
Vec3d m_total_position{ Vec3d::Zero() };
|
||||
|
||||
@ -711,7 +712,6 @@ public:
|
||||
{
|
||||
GLModel m_model;
|
||||
Vec3f m_world_position;
|
||||
Transform3f m_world_transform;
|
||||
// For seams, the position of the marker is on the last endpoint of the toolpath containing it.
|
||||
// This offset is used to show the correct value of tool position in the "ToolPosition" window.
|
||||
// See implementation of render() method
|
||||
@ -721,13 +721,15 @@ public:
|
||||
// z offset of the model
|
||||
float m_model_z_offset{ 0.5f };
|
||||
bool m_visible{ true };
|
||||
bool m_fixed_screen_size{ false };
|
||||
float m_scale_factor{ 1.0f };
|
||||
|
||||
public:
|
||||
void init();
|
||||
|
||||
const BoundingBoxf3& get_bounding_box() const { return m_model.get_bounding_box(); }
|
||||
|
||||
void set_world_position(const Vec3f& position);
|
||||
void set_world_position(const Vec3f& position) { m_world_position = position; }
|
||||
void set_world_offset(const Vec3f& offset) { m_world_offset = offset; }
|
||||
void set_z_offset(float z_offset) { m_z_offset = z_offset; }
|
||||
|
||||
|
@ -164,6 +164,16 @@ void ToolMarker::render()
|
||||
glsafe(glBindVertexArray(curr_vertex_array));
|
||||
}
|
||||
|
||||
bool ToolMarker::is_enabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void ToolMarker::enable(bool value)
|
||||
{
|
||||
m_enabled = value;
|
||||
}
|
||||
|
||||
const Vec3f& ToolMarker::get_position() const
|
||||
{
|
||||
return m_position;
|
||||
|
@ -27,6 +27,9 @@ public:
|
||||
void init(uint16_t resolution, float tip_radius, float tip_height, float stem_radius, float stem_height);
|
||||
void render();
|
||||
|
||||
bool is_enabled() const;
|
||||
void enable(bool value);
|
||||
|
||||
const Vec3f& get_position() const;
|
||||
void set_position(const Vec3f& position);
|
||||
|
||||
@ -40,6 +43,7 @@ public:
|
||||
void set_alpha(float alpha);
|
||||
|
||||
private:
|
||||
bool m_enabled{ false };
|
||||
Vec3f m_position{ 0.0f, 0.0f, 0.0f };
|
||||
float m_offset_z{ 0.5f };
|
||||
Color m_color{ 1.0f, 1.0f, 1.0f };
|
||||
|
@ -134,6 +134,16 @@ void Viewer::set_cog_marker_scale_factor(float factor)
|
||||
m_impl.set_cog_marker_scale_factor(factor);
|
||||
}
|
||||
|
||||
bool Viewer::is_tool_marker_enabled() const
|
||||
{
|
||||
return m_impl.is_tool_marker_enabled();
|
||||
}
|
||||
|
||||
void Viewer::enable_tool_marker(bool value)
|
||||
{
|
||||
m_impl.enable_tool_marker(value);
|
||||
}
|
||||
|
||||
const Vec3f& Viewer::get_tool_marker_position() const
|
||||
{
|
||||
return m_impl.get_tool_marker_position();
|
||||
|
@ -80,6 +80,9 @@ public:
|
||||
float get_cog_marker_scale_factor() const;
|
||||
void set_cog_marker_scale_factor(float factor);
|
||||
|
||||
bool is_tool_marker_enabled() const;
|
||||
void enable_tool_marker(bool value);
|
||||
|
||||
const Vec3f& get_tool_marker_position() const;
|
||||
void set_tool_marker_position(const Vec3f& position);
|
||||
|
||||
|
@ -1056,6 +1056,11 @@ float ViewerImpl::get_cog_marker_scale_factor() const
|
||||
return m_cog_marker_scale_factor;
|
||||
}
|
||||
|
||||
bool ViewerImpl::is_tool_marker_enabled() const
|
||||
{
|
||||
return m_tool_marker.is_enabled();
|
||||
}
|
||||
|
||||
const Vec3f& ViewerImpl::get_tool_marker_position() const
|
||||
{
|
||||
return m_tool_marker.get_position();
|
||||
@ -1086,6 +1091,11 @@ void ViewerImpl::set_cog_marker_scale_factor(float factor)
|
||||
m_cog_marker_scale_factor = std::max(factor, 0.001f);
|
||||
}
|
||||
|
||||
void ViewerImpl::enable_tool_marker(bool value)
|
||||
{
|
||||
m_tool_marker.enable(value);
|
||||
}
|
||||
|
||||
void ViewerImpl::set_tool_marker_position(const Vec3f& position)
|
||||
{
|
||||
m_tool_marker.set_position(position);
|
||||
@ -1449,6 +1459,9 @@ void ViewerImpl::render_tool_marker(const Mat4x4f& view_matrix, const Mat4x4f& p
|
||||
if (m_tool_marker_shader_id == 0)
|
||||
return;
|
||||
|
||||
if (!m_tool_marker.is_enabled())
|
||||
return;
|
||||
|
||||
int curr_shader;
|
||||
glsafe(glGetIntegerv(GL_CURRENT_PROGRAM, &curr_shader));
|
||||
const bool curr_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||
|
@ -110,6 +110,7 @@ public:
|
||||
#if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
Vec3f get_cog_marker_position() const;
|
||||
float get_cog_marker_scale_factor() const;
|
||||
bool is_tool_marker_enabled() const;
|
||||
const Vec3f& get_tool_marker_position() const;
|
||||
float get_tool_marker_offset_z() const;
|
||||
float get_tool_marker_scale_factor() const;
|
||||
@ -122,6 +123,7 @@ public:
|
||||
//
|
||||
#if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
void set_cog_marker_scale_factor(float factor);
|
||||
void enable_tool_marker(bool value);
|
||||
void set_tool_marker_position(const Vec3f& position);
|
||||
void set_tool_marker_offset_z(float offset_z);
|
||||
void set_tool_marker_scale_factor(float factor);
|
||||
|
Loading…
x
Reference in New Issue
Block a user