mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-05 14:40:41 +08:00
Per letter emboss with align
This commit is contained in:
parent
28b526167a
commit
43294950bd
@ -1870,19 +1870,19 @@ std::vector<double> Emboss::calculate_angles(int32_t distance, const PolygonPoin
|
||||
return result;
|
||||
}
|
||||
|
||||
PolygonPoints Emboss::sample_slice(const TextLine &slice, const BoundingBoxes &bbs, int32_t center_x, double scale)
|
||||
PolygonPoints Emboss::sample_slice(const TextLine &slice, const BoundingBoxes &bbs, double scale)
|
||||
{
|
||||
// find BB in center of line
|
||||
size_t first_right_index = 0;
|
||||
for (const BoundingBox &bb : bbs)
|
||||
if (bb.min.x() > center_x) {
|
||||
if (bb.min.x() > 0) {
|
||||
break;
|
||||
} else {
|
||||
++first_right_index;
|
||||
}
|
||||
|
||||
PolygonPoints samples(bbs.size());
|
||||
int32_t shapes_x_cursor = center_x;
|
||||
int32_t shapes_x_cursor = 0;
|
||||
|
||||
PolygonPoint cursor = slice.start; //copy
|
||||
|
||||
@ -1908,7 +1908,7 @@ PolygonPoints Emboss::sample_slice(const TextLine &slice, const BoundingBoxes &b
|
||||
samples[index] = create_sample(bbs[index], is_reverse);
|
||||
|
||||
// calc transformation for letters on the Left side from center
|
||||
shapes_x_cursor = center_x;
|
||||
shapes_x_cursor = 0;
|
||||
cursor = slice.start; // copy
|
||||
is_reverse = false;
|
||||
for (size_t index_plus_one = first_right_index; index_plus_one > 0; --index_plus_one) {
|
||||
|
@ -427,10 +427,9 @@ namespace Emboss
|
||||
/// </summary>
|
||||
/// <param name="slice">Polygon and start point</param>
|
||||
/// <param name="bbs">Bounding boxes of letter on one line</param>
|
||||
/// <param name="center_x">Center x coor of bbs line</param>
|
||||
/// <param name="scale">Scale for bbs</param>
|
||||
/// <returns>Sampled polygon by bounding boxes</returns>
|
||||
PolygonPoints sample_slice(const TextLine &slice, const BoundingBoxes &bbs, int32_t center_x, double scale);
|
||||
PolygonPoints sample_slice(const TextLine &slice, const BoundingBoxes &bbs, double scale);
|
||||
|
||||
/// <summary>
|
||||
/// Calculate angle for polygon point
|
||||
|
@ -236,8 +236,9 @@ static bool draw_button(const IconManager::VIcons& icons, IconType type, bool di
|
||||
/// </summary>
|
||||
/// <param name="camera">Define view vector</param>
|
||||
/// <param name="canvas">Containe Selected Model to modify</param>
|
||||
/// <param name="keep_up">Keep same up vector</param>
|
||||
/// <returns>True when apply change otherwise false</returns>
|
||||
static bool apply_camera_dir(const Camera &camera, GLCanvas3D &canvas);
|
||||
static bool apply_camera_dir(const Camera &camera, GLCanvas3D &canvas, bool keep_up);
|
||||
|
||||
} // namespace priv
|
||||
|
||||
@ -3201,11 +3202,16 @@ void GLGizmoEmboss::draw_advanced()
|
||||
}
|
||||
}
|
||||
|
||||
if (exist_change) {
|
||||
m_style_manager.clear_glyphs_cache();
|
||||
process();
|
||||
}
|
||||
|
||||
if (ImGui::Button(_u8L("Set text to face camera").c_str())) {
|
||||
assert(get_selected_volume(m_parent.get_selection()) == m_volume);
|
||||
const Camera &cam = wxGetApp().plater()->get_camera();
|
||||
bool use_surface = m_style_manager.get_style().prop.use_surface;
|
||||
if (priv::apply_camera_dir(cam, m_parent) && use_surface)
|
||||
const Camera &cam = wxGetApp().plater()->get_camera();
|
||||
bool use_surface = m_style_manager.get_style().prop.use_surface;
|
||||
if (priv::apply_camera_dir(cam, m_parent, m_keep_up) && use_surface)
|
||||
process();
|
||||
} else if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("%s", _u8L("Orient the text towards the camera.").c_str());
|
||||
@ -3218,7 +3224,7 @@ void GLGizmoEmboss::draw_advanced()
|
||||
if (!m_text_lines.is_init())
|
||||
init_text_lines();
|
||||
}
|
||||
exist_change = true;
|
||||
process();
|
||||
} else if (ImGui::IsItemHovered()) {
|
||||
if (*per_glyph) {
|
||||
ImGui::SetTooltip("%s", _u8L("Set global orientation for whole text.").c_str());
|
||||
@ -3234,6 +3240,7 @@ void GLGizmoEmboss::draw_advanced()
|
||||
ImGui::SetNextItemWidth(100);
|
||||
if (ImGui::SliderFloat("##base_line_y_offset", &m_text_lines.offset, -10.f, 10.f, "%f mm")) {
|
||||
init_text_lines();
|
||||
process();
|
||||
} else if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip("%s", _u8L("Move base line (up/down) for allign letters").c_str());
|
||||
|
||||
@ -3253,13 +3260,10 @@ void GLGizmoEmboss::draw_advanced()
|
||||
int selected_align = static_cast<int>(font_prop.align);
|
||||
if (ImGui::Combo("align", &selected_align, align_names, IM_ARRAYSIZE(align_names))) {
|
||||
font_prop.align = static_cast<FontProp::Align>(selected_align);
|
||||
}
|
||||
|
||||
|
||||
if (exist_change) {
|
||||
m_style_manager.clear_glyphs_cache();
|
||||
// TODO: move with text in finalize to not change position
|
||||
process();
|
||||
}
|
||||
|
||||
#ifdef ALLOW_DEBUG_MODE
|
||||
ImGui::Text("family = %s", (font_prop.family.has_value() ?
|
||||
font_prop.family->c_str() :
|
||||
@ -3743,8 +3747,7 @@ void priv::change_window_position(std::optional<ImVec2>& output_window_offset, b
|
||||
output_window_offset = ImVec2(-1, -1); // Cannot
|
||||
}
|
||||
|
||||
|
||||
bool priv::apply_camera_dir(const Camera &camera, GLCanvas3D &canvas) {
|
||||
bool priv::apply_camera_dir(const Camera &camera, GLCanvas3D &canvas, bool keep_up) {
|
||||
const Vec3d &cam_dir = camera.get_dir_forward();
|
||||
|
||||
Selection &sel = canvas.get_selection();
|
||||
|
@ -457,11 +457,13 @@ template<typename Fnc> TriangleMesh create_mesh_per_glyph(DataBase &input, Fnc w
|
||||
if (shapes.empty())
|
||||
return {};
|
||||
|
||||
const FontFile &ff = *font.font_file;
|
||||
double shape_scale = get_shape_scale(prop, ff);
|
||||
align_shape(prop.align, shapes);
|
||||
|
||||
BoundingBox extents; // whole text to find center
|
||||
// separate lines of text to vector
|
||||
const FontFile &ff = *font.font_file;
|
||||
double shape_scale = get_shape_scale(prop, ff);
|
||||
|
||||
// Precalculate bounding boxes of glyphs
|
||||
// Separate lines of text to vector of Bounds
|
||||
std::vector<BoundingBoxes> bbs(count_lines);
|
||||
size_t text_line_index = 0;
|
||||
// s_i .. shape index
|
||||
@ -470,7 +472,6 @@ template<typename Fnc> TriangleMesh create_mesh_per_glyph(DataBase &input, Fnc w
|
||||
BoundingBox bb;
|
||||
if (!shape.empty()) {
|
||||
bb = get_extents(shape);
|
||||
extents.merge(bb);
|
||||
}
|
||||
BoundingBoxes &line_bbs = bbs[text_line_index];
|
||||
line_bbs.push_back(bb);
|
||||
@ -487,14 +488,13 @@ template<typename Fnc> TriangleMesh create_mesh_per_glyph(DataBase &input, Fnc w
|
||||
double em_2_mm = prop.size_in_mm / 2.;
|
||||
int32_t em_2_polygon = static_cast<int32_t>(std::round(scale_(em_2_mm)));
|
||||
|
||||
Point center = extents.center();
|
||||
size_t s_i_offset = 0; // shape index offset(for next lines)
|
||||
indexed_triangle_set result;
|
||||
for (text_line_index = 0; text_line_index < input.text_lines.size(); ++text_line_index) {
|
||||
const BoundingBoxes &line_bbs = bbs[text_line_index];
|
||||
const TextLine &line = input.text_lines[text_line_index];
|
||||
// IMPROVE: do not precalculate samples do it inline - store result its
|
||||
PolygonPoints samples = sample_slice(line, line_bbs, center.x(), shape_scale);
|
||||
PolygonPoints samples = sample_slice(line, line_bbs, shape_scale);
|
||||
std::vector<double> angles = calculate_angles(em_2_polygon, samples, line.polygon);
|
||||
|
||||
for (size_t i = 0; i < line_bbs.size(); ++i) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user