Horizon
canvas3d_base.hpp
1 #pragma once
2 #include <glm/glm.hpp>
3 #include "common/common.hpp"
4 #include "canvas_mesh.hpp"
5 #include "canvas/appearance.hpp"
6 #include "util/uuid.hpp"
7 #include <mutex>
8 #include "cover.hpp"
9 #include "face.hpp"
10 #include "wall.hpp"
11 #include "background.hpp"
12 
13 namespace horizon {
14 
15 class Canvas3DBase {
16 public:
17  Canvas3DBase();
18  friend class CoverRenderer;
19  friend class WallRenderer;
20  friend class FaceRenderer;
21  friend class BackgroundRenderer;
22  CanvasMesh ca;
23  Color background_top_color;
24  Color background_bottom_color;
25  Color get_layer_color(int layer) const;
26 
27  bool show_solder_mask = true;
28  bool show_silkscreen = true;
29  bool show_substrate = true;
30  bool show_models = true;
31  bool show_dnp_models = false;
32  bool show_solder_paste = true;
33  bool use_layer_colors = false;
34  Color solder_mask_color = {0, .5, 0};
35  Color substrate_color = {.2, .15, 0};
36  float explode = 0;
37  float highlight_intensity = .5;
38 
39  float cam_azimuth = 90;
40  float cam_elevation = 45;
41  float cam_distance = 20;
42  float cam_fov = 45;
43  glm::vec2 center;
44 
45 
46  enum class Projection { PERSP, ORTHO };
47  Projection projection = Projection::PERSP;
48 
49  class FaceVertex {
50  public:
51  FaceVertex(float ix, float iy, float iz, uint8_t ir, uint8_t ig, uint8_t ib)
52  : x(ix), y(iy), z(iz), r(ir), g(ig), b(ib), _pad(0)
53  {
54  }
55  float x;
56  float y;
57  float z;
58 
59  uint8_t r;
60  uint8_t g;
61  uint8_t b;
62  uint8_t _pad;
63  } __attribute__((packed));
64 
65  class ModelTransform {
66  public:
67  ModelTransform(float ix, float iy, float a, bool flip, bool highlight)
68  : x(ix), y(iy), angle(a), flags(flip | (highlight << 1))
69  {
70  }
71  float x;
72  float y;
73  uint16_t angle;
74  uint16_t flags;
75 
76  float model_x = 0;
77  float model_y = 0;
78  float model_z = 0;
79  uint16_t model_roll = 0;
80  uint16_t model_pitch = 0;
81  uint16_t model_yaw = 0;
82  } __attribute__((packed));
83  void view_all();
84  void clear_3d_models();
85 
86 protected:
87  Appearance appearance;
88 
89  float width = 100;
90  float height = 100;
91 
92  CoverRenderer cover_renderer;
93  WallRenderer wall_renderer;
94  FaceRenderer face_renderer;
95  BackgroundRenderer background_renderer;
96 
97  void a_realize();
98  void resize_buffers();
99  void push();
100  enum class RenderBackground { YES, NO };
101  void render(RenderBackground mode = RenderBackground::YES);
102  virtual int a_get_scale_factor() const;
103  void prepare();
104  void prepare_packages();
105 
106  unsigned int num_samples = 1;
107 
108  const class Board *brd = nullptr;
109 
110  std::set<UUID> packages_highlight;
111 
112  void load_3d_model(const std::string &filename, const std::string &filename_abs);
113 
114  std::map<std::string, std::string> get_model_filenames(class IPool &pool);
115 
116  std::mutex models_loading_mutex;
117 
118  void update_max_package_height();
119 
120 private:
121  float get_layer_offset(int layer) const;
122  float get_layer_thickness(int layer) const;
123  bool layer_is_visible(int layer) const;
124 
125  std::pair<glm::vec3, glm::vec3> bbox;
126 
127  GLuint renderbuffer;
128  GLuint fbo;
129  GLuint depthrenderbuffer;
130 
131  glm::mat4 viewmat;
132  glm::mat4 projmat;
133  glm::vec3 cam_normal;
134 
135  float package_height_max = 0;
136  std::vector<FaceVertex> face_vertex_buffer; // vertices of all models, sequentially
137  std::vector<unsigned int> face_index_buffer; // indexes face_vertex_buffer to form triangles
138  std::map<std::string, std::pair<size_t, size_t>> models; // key: filename value: first: offset in face_index_buffer
139  // second: no of indexes
140 
141  std::vector<ModelTransform> package_transforms; // position and rotation of
142  // all board packages,
143  // grouped by package
144  std::map<std::pair<std::string, bool>, std::pair<size_t, size_t>>
145  package_transform_idxs; // key: first: model filename second: nopopulate
146  // value: first: offset in package_transforms second: no of items
147 
148  float get_magic_number() const;
149 };
150 
151 } // namespace horizon
libzip::uint8_t
zip_uint8_t uint8_t
zip_uint8_t typedef.
Definition: zip.hpp:78
libzip::uint16_t
zip_uint16_t uint16_t
zip_uint16_t typedef.
Definition: zip.hpp:88