Welcome to mirror list, hosted at ThFree Co, Russian Federation.

3DBed.hpp « GUI « slic3r « src - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 61f01f0217e0dd35619a2528def0d74567f3f4bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef slic3r_3DBed_hpp_
#define slic3r_3DBed_hpp_

#include "GLTexture.hpp"
#include "3DScene.hpp"
#if ENABLE_WORLD_COORDINATE_SHOW_AXES
#include "CoordAxes.hpp"
#else
#include "GLModel.hpp"
#endif // ENABLE_WORLD_COORDINATE_SHOW_AXES

#include "libslic3r/BuildVolume.hpp"
#if ENABLE_LEGACY_OPENGL_REMOVAL
#include "libslic3r/ExPolygon.hpp"
#endif // ENABLE_LEGACY_OPENGL_REMOVAL

#include <tuple>
#include <array>

namespace Slic3r {
namespace GUI {

class GLCanvas3D;

#if !ENABLE_LEGACY_OPENGL_REMOVAL
class GeometryBuffer
{
    struct Vertex
    {
        Vec3f position{ Vec3f::Zero() };
        Vec2f tex_coords{ Vec2f::Zero() };
    };

    std::vector<Vertex> m_vertices;

public:
    bool set_from_triangles(const std::vector<Vec2f> &triangles, float z);
    bool set_from_lines(const Lines& lines, float z);

    const float* get_vertices_data() const;
    unsigned int get_vertices_data_size() const { return (unsigned int)m_vertices.size() * get_vertex_data_size(); }
    unsigned int get_vertex_data_size() const { return (unsigned int)(5 * sizeof(float)); }
    size_t get_position_offset() const { return 0; }
    size_t get_tex_coords_offset() const { return (size_t)(3 * sizeof(float)); }
    unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size(); }
};
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL

class Bed3D
{
#if !ENABLE_WORLD_COORDINATE_SHOW_AXES
    class Axes
    {
    public:
        static const float DefaultStemRadius;
        static const float DefaultStemLength;
        static const float DefaultTipRadius;
        static const float DefaultTipLength;

    private:
        Vec3d m_origin{ Vec3d::Zero() };
        float m_stem_length{ DefaultStemLength };
        GLModel m_arrow;

    public:
        const Vec3d& get_origin() const { return m_origin; }
        void set_origin(const Vec3d& origin) { m_origin = origin; }
        void set_stem_length(float length) {
            m_stem_length = length;
            m_arrow.reset();
        }
        float get_total_length() const { return m_stem_length + DefaultTipLength; }
        void render();
    };
#endif // !ENABLE_WORLD_COORDINATE_SHOW_AXES

public:
    enum class Type : unsigned char
    {
        // The print bed model and texture are available from some printer preset.
        System,
        // The print bed model is unknown, thus it is rendered procedurally.
        Custom
    };

private:
    BuildVolume m_build_volume;
    Type m_type{ Type::Custom };
    std::string m_texture_filename;
    std::string m_model_filename;
    // Print volume bounding box exteded with axes and model.
    BoundingBoxf3 m_extended_bounding_box;
#if ENABLE_LEGACY_OPENGL_REMOVAL
    // Print bed polygon
    ExPolygon m_contour;
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
    // Slightly expanded print bed polygon, for collision detection.
    Polygon m_polygon;
#if ENABLE_LEGACY_OPENGL_REMOVAL
    GLModel m_triangles;
    GLModel m_gridlines;
    GLModel m_contourlines;
#else
    GeometryBuffer m_triangles;
    GeometryBuffer m_gridlines;
    GeometryBuffer m_contourlines;
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
    GLTexture m_texture;
    // temporary texture shown until the main texture has still no levels compressed
    GLTexture m_temp_texture;
    GLModel m_model;
    Vec3d m_model_offset{ Vec3d::Zero() };
#if !ENABLE_LEGACY_OPENGL_REMOVAL
    unsigned int m_vbo_id{ 0 };
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_WORLD_COORDINATE_SHOW_AXES
    CoordAxes m_axes;
#else
    Axes m_axes;
#endif // ENABLE_WORLD_COORDINATE_SHOW_AXES

    float m_scale_factor{ 1.0f };

public:
    Bed3D() = default;
#if ENABLE_LEGACY_OPENGL_REMOVAL
    ~Bed3D() = default;
#else
    ~Bed3D() { release_VBOs(); }
#endif // ENABLE_LEGACY_OPENGL_REMOVAL

    // Update print bed model from configuration.
    // Return true if the bed shape changed, so the calee will update the UI.
    //FIXME if the build volume max print height is updated, this function still returns zero
    // as this class does not use it, thus there is no need to update the UI.
    bool set_shape(const Pointfs& bed_shape, const double max_print_height, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom = false);

    // Build volume geometry for various collision detection tasks.
    const BuildVolume& build_volume() const { return m_build_volume; }

    // Was the model provided, or was it generated procedurally?
    Type get_type() const { return m_type; }
    // Was the model generated procedurally?
    bool is_custom() const { return m_type == Type::Custom; }

    // Bounding box around the print bed, axes and model, for rendering.
    const BoundingBoxf3& extended_bounding_box() const { return m_extended_bounding_box; }

    // Check against an expanded 2d bounding box.
    //FIXME shall one check against the real build volume?
    bool contains(const Point& point) const;
    Point point_projection(const Point& point) const;

#if ENABLE_GL_SHADERS_ATTRIBUTES
    void render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture);
    void render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor);
#else
    void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture);
    void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES

private:
    // Calculate an extended bounding box from axes and current model for visualization purposes.
    BoundingBoxf3 calc_extended_bounding_box() const;
#if ENABLE_LEGACY_OPENGL_REMOVAL
    void init_triangles();
    void init_gridlines();
    void init_contourlines();
#else
    void calc_triangles(const ExPolygon& poly);
    void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
    void calc_contourlines(const ExPolygon& poly);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
    static std::tuple<Type, std::string, std::string> detect_type(const Pointfs& shape);
#if ENABLE_GL_SHADERS_ATTRIBUTES
    void render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor,
        bool show_axes, bool show_texture, bool picking);
#else
    void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
        bool show_axes, bool show_texture, bool picking);
#endif // ENABLE_GL_SHADERS_ATTRIBUTES
    void render_axes();
#if ENABLE_GL_SHADERS_ATTRIBUTES
    void render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture);
    void render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix);
    void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix);
    void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking);
    void render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix);
    void render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix);
#else
    void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture);
    void render_texture(bool bottom, GLCanvas3D& canvas);
    void render_model();
    void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking);
    void render_default(bool bottom, bool picking, bool show_texture);
    void render_contour();
#endif // ENABLE_GL_SHADERS_ATTRIBUTES

#if !ENABLE_LEGACY_OPENGL_REMOVAL
    void release_VBOs();
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
};

} // GUI
} // Slic3r

#endif // slic3r_3DBed_hpp_