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: 98da0354231a1d472b69dfe7673c9b3ea6631782 (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
#ifndef slic3r_3DBed_hpp_
#define slic3r_3DBed_hpp_

#include "GLTexture.hpp"
#include "3DScene.hpp"
#if ENABLE_TEXTURES_FROM_SVG
#include "GLShader.hpp"
#endif // ENABLE_TEXTURES_FROM_SVG

class GLUquadric;
typedef class GLUquadric GLUquadricObj;

namespace Slic3r {
namespace GUI {

class GeometryBuffer
{
#if ENABLE_TEXTURES_FROM_SVG
    struct Vertex
    {
        float position[3];
        float tex_coords[2];

        Vertex()
        {
            position[0] = 0.0f; position[1] = 0.0f; position[2] = 0.0f;
            tex_coords[0] = 0.0f; tex_coords[1] = 0.0f;
        }
    };

    std::vector<Vertex> m_vertices;
#else
    std::vector<float> m_vertices;
    std::vector<float> m_tex_coords;
#endif // ENABLE_TEXTURES_FROM_SVG

public:
    bool set_from_triangles(const Polygons& triangles, float z, bool generate_tex_coords);
    bool set_from_lines(const Lines& lines, float z);

#if ENABLE_TEXTURES_FROM_SVG
    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)); }
    unsigned int get_position_offset() const { return 0; }
    unsigned int get_tex_coords_offset() const { return (unsigned int)(3 * sizeof(float)); }
    unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size(); }
#else
    const float* get_vertices() const { return m_vertices.data(); }
    const float* get_tex_coords() const { return m_tex_coords.data(); }
    unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size() / 3; }
#endif // ENABLE_TEXTURES_FROM_SVG
};

class Bed3D
{
    struct Axes
    {
        static const double Radius;
        static const double ArrowBaseRadius;
        static const double ArrowLength;
        Vec3d origin;
        Vec3d length;
        GLUquadricObj* m_quadric;

        Axes();
        ~Axes();

        void render() const;

    private:
        void render_axis(double length) const;
    };

public:
    enum EType : unsigned char
    {
        MK2,
        MK3,
        SL1,
        Custom,
        Num_Types
    };

private:
    EType m_type;
    Pointfs m_shape;
    mutable BoundingBoxf3 m_bounding_box;
    mutable BoundingBoxf3 m_extended_bounding_box;
    Polygon m_polygon;
    GeometryBuffer m_triangles;
    GeometryBuffer m_gridlines;
#if ENABLE_TEXTURES_FROM_SVG
    mutable GLTexture m_texture;
    mutable Shader m_shader;
    mutable unsigned int m_vbo_id;
#else
    mutable GLTexture m_top_texture;
    mutable GLTexture m_bottom_texture;
#endif // ENABLE_TEXTURES_FROM_SVG
    mutable GLBed m_model;
    Axes m_axes;

    mutable float m_scale_factor;

public:
    Bed3D();
#if ENABLE_TEXTURES_FROM_SVG
    ~Bed3D() { reset(); }
#endif // ENABLE_TEXTURES_FROM_SVG

    EType get_type() const { return m_type; }

    bool is_prusa() const { return (m_type == MK2) || (m_type == MK3) || (m_type == SL1); }
    bool is_custom() const { return m_type == Custom; }

    const Pointfs& get_shape() const { return m_shape; }
    // Return true if the bed shape changed, so the calee will update the UI.
    bool set_shape(const Pointfs& shape);

    const BoundingBoxf3& get_bounding_box(bool extended) const { return extended ? m_extended_bounding_box : m_bounding_box; }
    bool contains(const Point& point) const;
    Point point_projection(const Point& point) const;

    void render(float theta, bool useVBOs, float scale_factor) const;
    void render_axes() const;

private:
    void calc_bounding_boxes() const;
    void calc_triangles(const ExPolygon& poly);
    void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
    EType detect_type(const Pointfs& shape) const;
#if ENABLE_TEXTURES_FROM_SVG
    void render_prusa(const std::string& key, bool bottom) const;
    void render_prusa_shader(bool transparent) const;
#else
    void render_prusa(const std::string &key, float theta, bool useVBOs) const;
#endif // ENABLE_TEXTURES_FROM_SVG
    void render_custom() const;
#if ENABLE_TEXTURES_FROM_SVG
    void reset();
#endif // ENABLE_TEXTURES_FROM_SVG
};

} // GUI
} // Slic3r

#endif // slic3r_3DBed_hpp_