Sat, 08 Apr 2023 12:53:15 +0300
Fix line type 0 format regular expression
17 | 1 | #pragma once |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
2 | #include "src/basics.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
3 | #include "src/documentmanager.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
4 | #include "src/types/boundingbox.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
5 | #include "src/gl/common.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
6 | #include "src/gl/compiler.h" |
291
42b4953dff85
Let's bring GLEW back after all
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
264
diff
changeset
|
7 | #include <QOpenGLWidget> |
17 | 8 | |
217
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
9 | class PartRenderer final : public QOpenGLWidget |
17 | 10 | { |
21 | 11 | Q_OBJECT |
338 | 12 | QTextDocument* const model; |
217
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
13 | DocumentManager* const documents; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
14 | const ColorTable& colorTable; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
15 | BoundingBox boundingBox; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
16 | gl::ModelShaders shaders; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
17 | ModelId highlighted = {0}; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
18 | glm::mat4 projectionMatrix; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
19 | glm::mat4 viewMatrix; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
20 | glm::mat4 modelMatrix; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
21 | glm::vec4 viewportVector; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
22 | glm::quat modelQuaternion; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
23 | QPoint lastMousePosition; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
24 | int totalMouseMove = 0; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
25 | gl::RenderPreferences renderPreferences; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
26 | double zoom = 1.0; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
27 | bool initialized = false; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
28 | bool needBuild = true; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
29 | std::vector<RenderLayer*> activeRenderLayers; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
30 | std::vector<RenderLayer*> inactiveRenderLayers; |
313
c24d87f64bed
Improve click handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
309
diff
changeset
|
31 | std::chrono::time_point<std::chrono::steady_clock> lastClickTime; |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
32 | bool frozen = false; |
17 | 33 | public: |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
34 | PartRenderer( |
338 | 35 | QTextDocument* model, |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
36 | DocumentManager* documents, |
205 | 37 | const ColorTable& colorTable, |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
38 | QWidget* parent = nullptr); |
26 | 39 | ~PartRenderer() override; |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
40 | void setRenderPreferences(const gl::RenderPreferences& newPreferences); |
200 | 41 | ModelId getHighlightedObject() const; |
215
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
42 | void addRenderLayer(RenderLayer* layer); |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
43 | void setLayerEnabled(RenderLayer* layer, bool enabled); |
217
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
44 | std::optional<glm::vec3> screenToModelCoordinates(const QPointF& point, const Plane& plane) const; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
45 | QPointF modelToScreenCoordinates(const glm::vec3& point) const; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
46 | bool isDark() const; |
333
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
322
diff
changeset
|
47 | std::int32_t pick(QPoint where); |
07e65a4c6611
Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
322
diff
changeset
|
48 | void setSelection(const QSet<std::int32_t>& selectedIds); |
313
c24d87f64bed
Improve click handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
309
diff
changeset
|
49 | glm::vec3 cameraVector(const QPointF& point) const; |
c24d87f64bed
Improve click handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
309
diff
changeset
|
50 | Line<3> cameraLine(const QPointF& point) const; |
112 | 51 | Q_SIGNALS: |
70 | 52 | void projectionMatrixChanged(const glm::mat4& newMatrix); |
53 | void modelMatrixChanged(const glm::mat4& newMatrix); | |
54 | void viewMatrixChanged(const glm::mat4& newMatrix); | |
61
4585d8d7a7ec
moved GridProgram to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
58
diff
changeset
|
55 | void renderPreferencesChanged(); |
237
10a6298f636f
Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
232
diff
changeset
|
56 | void message(const Message& message); |
17 | 57 | private: |
217
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
58 | void initializeGL() override; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
59 | void resizeGL(int width, int height) override; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
60 | void paintGL() override; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
61 | void mouseMoveEvent(QMouseEvent* event) override; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
62 | void mousePressEvent(QMouseEvent* event) override; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
63 | void mouseReleaseEvent(QMouseEvent* event) override; |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
64 | void keyReleaseEvent(QKeyEvent* event) override; |
217
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
65 | void wheelEvent(QWheelEvent* event) override; |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
66 | glm::vec3 unproject(const glm::vec3& win) const; |
37 | 67 | void setFragmentStyle(gl::FragmentStyle fragStyle); |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
68 | void renderScene(); |
31
b6df269a2c6b
fix remaining rendering control issues
Teemu Piippo <teemu@hecknology.net>
parents:
30
diff
changeset
|
69 | void updateViewMatrix(); |
55 | 70 | void updateModelMatrix(); |
86
4bec0525ef1b
PolygonObjectEditor can now modify the object properly
Teemu Piippo <teemu@hecknology.net>
parents:
73
diff
changeset
|
71 | Q_SLOT void build(); |
26 | 72 | void renderVao(const gl::ArrayClass arrayClass); |
73 | void checkForGLErrors(); | |
17 | 74 | }; |
322
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
75 | |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
76 | inline QVector<QPointF> convertWorldPointsToScreenPoints( |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
77 | const std::vector<glm::vec3> &worldPoints, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
78 | const PartRenderer* renderer) |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
79 | { |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
80 | QVector<QPointF> points2d; |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
81 | points2d.reserve(static_cast<int>(worldPoints.size())); |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
82 | for (const glm::vec3& point : worldPoints) |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
83 | { |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
84 | points2d.push_back(renderer->modelToScreenCoordinates(point)); |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
85 | } |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
86 | return points2d; |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
87 | } |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
88 | |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
89 | inline Winding worldPolygonWinding( |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
90 | const std::vector<glm::vec3> &points, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
91 | const PartRenderer* renderer) |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
92 | { |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
93 | return winding(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
94 | } |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
95 | |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
96 | inline void drawWorldPoint( |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
97 | QPainter* painter, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
98 | const glm::vec3& worldPoint, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
99 | const PartRenderer* renderer) |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
100 | { |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
101 | const QPointF center = renderer->modelToScreenCoordinates(worldPoint); |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
102 | painter->drawEllipse(inscribe(CircleF{center, 5})); |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
103 | } |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
104 | |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
105 | inline void drawWorldPolyline( |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
106 | QPainter *painter, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
107 | const std::vector<glm::vec3> &points, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
108 | const PartRenderer* renderer) |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
109 | { |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
110 | painter->drawPolyline(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
111 | } |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
112 | |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
113 | inline void drawWorldPolygon( |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
114 | QPainter* painter, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
115 | const std::vector<glm::vec3> &points, |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
116 | const PartRenderer* renderer) |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
117 | { |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
118 | painter->drawPolygon(QPolygonF{convertWorldPointsToScreenPoints(points, renderer)}); |
a39f454a3d7f
Reduce edittools.cpp further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
313
diff
changeset
|
119 | } |