mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 03:07:55 -06:00
Port Emboss & SVG gizmo from PrusaSlicer (#2819)
* Rework UI jobs to make them more understandable and flexible. * Update Orca specific jobs * Fix progress issue * Fix dark mode and window radius * Update cereal version from 1.2.2 to 1.3.0 (cherry picked from commit prusa3d/PrusaSlicer@057232a275) * Initial port of Emboss gizmo * Bump up CGAL version to 5.4 (cherry picked from commit prusa3d/PrusaSlicer@1bf9dee3e7) * Fix text rotation * Fix test dragging * Add text gizmo to right click menu * Initial port of SVG gizmo * Fix text rotation * Fix Linux build * Fix "from surface" * Fix -90 rotation * Fix icon path * Fix loading font with non-ascii name * Fix storing non-utf8 font descriptor in 3mf file * Fix filtering with non-utf8 characters * Emboss: Use Orca style input dialog * Fix build on macOS * Fix tooltip color in light mode * InputText: fixed incorrect padding when FrameBorder > 0. (ocornut/imgui#4794, ocornut/imgui#3781) InputTextMultiline: fixed vertical tracking with large values of FramePadding.y. (ocornut/imgui#3781, ocornut/imgui#4794) (cherry picked from commit ocornut/imgui@072caa4a90) (cherry picked from commit ocornut/imgui@bdd2a94315) * SVG: Use Orca style input dialog * Fix job progress update * Fix crash when select editing text in preview screen * Use Orca checkbox style * Fix issue that toolbar icons are kept regenerated * Emboss: Fix text & icon alignment * SVG: Fix text & icon alignment * Emboss: fix toolbar icon mouse hover state * Add a simple subtle outline effect by drawing back faces using wireframe mode * Disable selection outlines * Show outline in white if the model color is too dark * Make the outline algorithm more reliable * Enable cull face, which fix render on Linux * Fix `disable_cullface` * Post merge fix * Optimize selection rendering * Fix scale gizmo * Emboss: Fix text rotation if base object is scaled * Fix volume synchronize * Fix emboss rotation * Emboss: Fix advance toggle * Fix text position after reopened the project * Make font style preview darker * Make font style preview selector height shorter --------- Co-authored-by: tamasmeszaros <meszaros.q@gmail.com> Co-authored-by: ocornut <omarcornut@gmail.com> Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
parent
7a8e1929ee
commit
933aa3050b
197 changed files with 27190 additions and 2454 deletions
265
src/slic3r/GUI/Jobs/EmbossJob.hpp
Normal file
265
src/slic3r/GUI/Jobs/EmbossJob.hpp
Normal file
|
@ -0,0 +1,265 @@
|
|||
///|/ Copyright (c) Prusa Research 2021 - 2022 Oleksandra Iushchenko @YuSanka, Filip Sykala @Jony01
|
||||
///|/
|
||||
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef slic3r_EmbossJob_hpp_
|
||||
#define slic3r_EmbossJob_hpp_
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <libslic3r/Emboss.hpp>
|
||||
#include <libslic3r/EmbossShape.hpp> // ExPolygonsWithIds
|
||||
#include "libslic3r/Point.hpp" // Transform3d
|
||||
#include "libslic3r/ObjectID.hpp"
|
||||
|
||||
#include "slic3r/GUI/Camera.hpp"
|
||||
#include "slic3r/GUI/TextLines.hpp"
|
||||
|
||||
#include "Job.hpp"
|
||||
|
||||
// forward declarations
|
||||
namespace Slic3r {
|
||||
class TriangleMesh;
|
||||
class ModelVolume;
|
||||
enum class ModelVolumeType : int;
|
||||
class BuildVolume;
|
||||
namespace GUI {
|
||||
class RaycastManager;
|
||||
class Plater;
|
||||
class GLCanvas3D;
|
||||
class Worker;
|
||||
class Selection;
|
||||
}}
|
||||
|
||||
namespace Slic3r::GUI::Emboss {
|
||||
|
||||
/// <summary>
|
||||
/// Base data hold data for create emboss shape
|
||||
/// </summary>
|
||||
class DataBase
|
||||
{
|
||||
public:
|
||||
DataBase(const std::string& volume_name, std::shared_ptr<std::atomic<bool>> cancel)
|
||||
: volume_name(volume_name), cancel(std::move(cancel)) {}
|
||||
DataBase(const std::string& volume_name, std::shared_ptr<std::atomic<bool>> cancel, EmbossShape&& shape)
|
||||
: volume_name(volume_name), cancel(std::move(cancel)), shape(std::move(shape)){}
|
||||
DataBase(DataBase &&) = default;
|
||||
virtual ~DataBase() = default;
|
||||
|
||||
/// <summary>
|
||||
/// Create shape
|
||||
/// e.g. Text extract glyphs from font
|
||||
/// Not 'const' function because it could modify shape
|
||||
/// </summary>
|
||||
virtual EmbossShape& create_shape() { return shape; };
|
||||
|
||||
/// <summary>
|
||||
/// Write data how to reconstruct shape to volume
|
||||
/// </summary>
|
||||
/// <param name="volume">Data object for store emboss params</param>
|
||||
virtual void write(ModelVolume &volume) const;
|
||||
|
||||
// Define projection move
|
||||
// True (raised) .. move outside from surface (MODEL_PART)
|
||||
// False (engraved).. move into object (NEGATIVE_VOLUME)
|
||||
bool is_outside = true;
|
||||
|
||||
// Define per letter projection on one text line
|
||||
// [optional] It is not used when empty
|
||||
Slic3r::Emboss::TextLines text_lines = {};
|
||||
|
||||
// [optional] Define distance for surface
|
||||
// It is used only for flat surface (not cutted)
|
||||
// Position of Zero(not set value) differ for MODEL_PART and NEGATIVE_VOLUME
|
||||
std::optional<float> from_surface;
|
||||
|
||||
// new volume name
|
||||
std::string volume_name;
|
||||
|
||||
// flag that job is canceled
|
||||
// for time after process.
|
||||
std::shared_ptr<std::atomic<bool>> cancel;
|
||||
|
||||
// shape to emboss
|
||||
EmbossShape shape;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Hold neccessary data to create ModelVolume in job
|
||||
/// Volume is created on the surface of existing volume in object.
|
||||
/// NOTE: EmbossDataBase::font_file doesn't have to be valid !!!
|
||||
/// </summary>
|
||||
struct DataCreateVolume : public DataBase
|
||||
{
|
||||
// define embossed volume type
|
||||
ModelVolumeType volume_type;
|
||||
|
||||
// parent ModelObject index where to create volume
|
||||
ObjectID object_id;
|
||||
|
||||
// new created volume transformation
|
||||
Transform3d trmat;
|
||||
};
|
||||
using DataBasePtr = std::unique_ptr<DataBase>;
|
||||
|
||||
/// <summary>
|
||||
/// Hold neccessary data to update embossed text object in job
|
||||
/// </summary>
|
||||
struct DataUpdate
|
||||
{
|
||||
// Hold data about shape
|
||||
DataBasePtr base;
|
||||
|
||||
// unique identifier of volume to change
|
||||
ObjectID volume_id;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Update text shape in existing text volume
|
||||
/// Predict that there is only one runnig(not canceled) instance of it
|
||||
/// </summary>
|
||||
class UpdateJob : public Job
|
||||
{
|
||||
DataUpdate m_input;
|
||||
TriangleMesh m_result;
|
||||
|
||||
public:
|
||||
// move params to private variable
|
||||
explicit UpdateJob(DataUpdate &&input);
|
||||
|
||||
/// <summary>
|
||||
/// Create new embossed volume by m_input data and store to m_result
|
||||
/// </summary>
|
||||
/// <param name="ctl">Control containing cancel flag</param>
|
||||
void process(Ctl &ctl) override;
|
||||
|
||||
/// <summary>
|
||||
/// Update volume - change object_id
|
||||
/// </summary>
|
||||
/// <param name="canceled">Was process canceled.
|
||||
/// NOTE: Be carefull it doesn't care about
|
||||
/// time between finished process and started finalize part.</param>
|
||||
/// <param name="">unused</param>
|
||||
void finalize(bool canceled, std::exception_ptr &eptr) override;
|
||||
|
||||
/// <summary>
|
||||
/// Update text volume
|
||||
/// </summary>
|
||||
/// <param name="volume">Volume to be updated</param>
|
||||
/// <param name="mesh">New Triangle mesh for volume</param>
|
||||
/// <param name="base">Data to write into volume</param>
|
||||
static void update_volume(ModelVolume *volume, TriangleMesh &&mesh, const DataBase &base);
|
||||
};
|
||||
|
||||
struct SurfaceVolumeData
|
||||
{
|
||||
// Transformation of volume inside of object
|
||||
Transform3d transform;
|
||||
|
||||
struct ModelSource
|
||||
{
|
||||
// source volumes
|
||||
std::shared_ptr<const TriangleMesh> mesh;
|
||||
// Transformation of volume inside of object
|
||||
Transform3d tr;
|
||||
};
|
||||
using ModelSources = std::vector<ModelSource>;
|
||||
ModelSources sources;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Hold neccessary data to update embossed text object in job
|
||||
/// </summary>
|
||||
struct UpdateSurfaceVolumeData : public DataUpdate, public SurfaceVolumeData{};
|
||||
|
||||
/// <summary>
|
||||
/// Update text volume to use surface from object
|
||||
/// </summary>
|
||||
class UpdateSurfaceVolumeJob : public Job
|
||||
{
|
||||
UpdateSurfaceVolumeData m_input;
|
||||
TriangleMesh m_result;
|
||||
|
||||
public:
|
||||
// move params to private variable
|
||||
explicit UpdateSurfaceVolumeJob(UpdateSurfaceVolumeData &&input);
|
||||
void process(Ctl &ctl) override;
|
||||
void finalize(bool canceled, std::exception_ptr &eptr) override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Copied triangles from object to be able create mesh for cut surface from
|
||||
/// </summary>
|
||||
/// <param name="volume">Define embossed volume</param>
|
||||
/// <returns>Source data for cut surface from</returns>
|
||||
SurfaceVolumeData::ModelSources create_volume_sources(const ModelVolume &volume);
|
||||
|
||||
/// <summary>
|
||||
/// shorten params for start_crate_volume functions
|
||||
/// </summary>
|
||||
struct CreateVolumeParams
|
||||
{
|
||||
GLCanvas3D &canvas;
|
||||
|
||||
// Direction of ray into scene
|
||||
const Camera &camera;
|
||||
|
||||
// To put new object on the build volume
|
||||
const BuildVolume &build_volume;
|
||||
|
||||
// used to emplace job for execution
|
||||
Worker &worker;
|
||||
|
||||
// New created volume type
|
||||
ModelVolumeType volume_type;
|
||||
|
||||
// Contain AABB trees from scene
|
||||
RaycastManager &raycaster;
|
||||
|
||||
// Define which gizmo open on the success
|
||||
unsigned char gizmo; // GLGizmosManager::EType
|
||||
|
||||
// Volume define object to add new volume
|
||||
const GLVolume *gl_volume;
|
||||
|
||||
// Wanted additionl move in Z(emboss) direction of new created volume
|
||||
std::optional<float> distance = {};
|
||||
|
||||
// Wanted additionl rotation around Z of new created volume
|
||||
std::optional<float> angle = {};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Create new volume on position of mouse cursor
|
||||
/// </summary>
|
||||
/// <param name="plater_ptr">canvas + camera + bed shape + </param>
|
||||
/// <param name="data">Shape of emboss</param>
|
||||
/// <param name="volume_type">New created volume type</param>
|
||||
/// <param name="raycaster">Knows object in scene</param>
|
||||
/// <param name="gizmo">Define which gizmo open on the success - enum GLGizmosManager::EType</param>
|
||||
/// <param name="mouse_pos">Define position where to create volume</param>
|
||||
/// <param name="distance">Wanted additionl move in Z(emboss) direction of new created volume</param>
|
||||
/// <param name="angle">Wanted additionl rotation around Z of new created volume</param>
|
||||
/// <returns>True on success otherwise False</returns>
|
||||
bool start_create_volume(CreateVolumeParams &input, DataBasePtr data, const Vec2d &mouse_pos);
|
||||
|
||||
/// <summary>
|
||||
/// Same as previous function but without mouse position
|
||||
/// Need to suggest position or put near the selection
|
||||
/// </summary>
|
||||
bool start_create_volume_without_position(CreateVolumeParams &input, DataBasePtr data);
|
||||
|
||||
/// <summary>
|
||||
/// Start job for update embossed volume
|
||||
/// </summary>
|
||||
/// <param name="data">define update data</param>
|
||||
/// <param name="volume">Volume to be updated</param>
|
||||
/// <param name="selection">Keep model and gl_volumes - when start use surface volume must be selected</param>
|
||||
/// <param name="raycaster">Could cast ray to scene</param>
|
||||
/// <returns>True when start job otherwise false</returns>
|
||||
bool start_update_volume(DataUpdate &&data, const ModelVolume &volume, const Selection &selection, RaycastManager &raycaster);
|
||||
|
||||
} // namespace Slic3r::GUI
|
||||
|
||||
#endif // slic3r_EmbossJob_hpp_
|
Loading…
Add table
Add a link
Reference in a new issue