-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathpbrshaderwidget.h
146 lines (142 loc) · 5.38 KB
/
pbrshaderwidget.h
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
/*
* Copyright (c) 2020 Jeremy HU <jeremy-at-dust3d dot org>. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef AUTO_REMESHER_PBR_SHADER_WIDGET_H
#define AUTO_REMESHER_PBR_SHADER_WIDGET_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QMatrix4x4>
#include <QMutex>
#include <QVector2D>
#include <QTimer>
#include "pbrshadermesh.h"
#include "pbrshaderprogram.h"
#include "pbrshadermeshbinder.h"
class PbrShaderWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
signals:
void mouseRayChanged(const QVector3D &near, const QVector3D &far);
void mousePressed(QPoint globalPos);
void mouseReleased(QPoint globalPos);
void addMouseRadius(float radius);
void renderParametersChanged();
void xRotationChanged(int angle);
void yRotationChanged(int angle);
void zRotationChanged(int angle);
void eyePositionChanged(const QVector3D &eyePosition);
void moveToPositionChanged(const QVector3D &moveToPosition);
public:
PbrShaderWidget(QWidget *parent = 0);
~PbrShaderWidget();
static bool isTransparent()
{
return m_transparent;
}
static void setTransparent(bool t)
{
m_transparent = t;
}
void updateMesh(PbrShaderMesh *mesh);
void toggleWireframe();
bool isWireframeVisible();
void toggleRotation();
void toggleUvCheck();
void enableEnvironmentLight();
bool isEnvironmentLightEnabled();
void enableMove(bool enabled);
void enableZoom(bool enabled);
void enableMousePicking(bool enabled);
void setMoveAndZoomByWindow(bool byWindow);
void disableCullFace();
void setMoveToPosition(const QVector3D &moveToPosition);
bool inputMousePressEventFromOtherWidget(QMouseEvent *event);
bool inputMouseMoveEventFromOtherWidget(QMouseEvent *event);
bool inputWheelEventFromOtherWidget(QWheelEvent *event);
bool inputMouseReleaseEventFromOtherWidget(QMouseEvent *event);
QPoint convertInputPosFromOtherWidget(QMouseEvent *event);
void fetchCurrentToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
void updateToonNormalAndDepthMaps(QImage *normalMap, QImage *depthMap);
int widthInPixels();
int heightInPixels();
int xRotation();
int yRotation();
int zRotation();
const QVector3D &eyePosition();
const QVector3D &moveToPosition();
std::pair<QVector3D, QVector3D> mousePositionToMouseRay(const QPoint &mousePosition);
public slots:
void setXRotation(int angle);
void setYRotation(int angle);
void setZRotation(int angle);
void setEyePosition(const QVector3D &eyePosition);
void cleanup();
void zoom(float delta);
void setMousePickTargetPositionInModelSpace(QVector3D position);
void setMousePickRadius(float radius);
void reRender();
void canvasResized();
protected:
void initializeGL() override;
void paintGL() override;
void resizeGL(int width, int height) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
int m_xRotation = m_defaultXRotation;
int m_yRotation = m_defaultYRotation;
int m_zRotation = m_defaultZRotation;
PbrShaderProgram *m_program = nullptr;
bool m_moveStarted = false;
bool m_moveEnabled = true;
bool m_zoomEnabled = true;
bool m_mousePickingEnabled = false;
QVector3D m_mousePickTargetPositionInModelSpace;
QPoint m_lastPos;
PbrShaderMeshBinder m_meshBinder;
QMatrix4x4 m_projection;
QMatrix4x4 m_camera;
QMatrix4x4 m_world;
float m_mousePickRadius = 0.0;
QVector3D m_eyePosition = m_defaultEyePosition;
static bool m_transparent;
static float m_minZoomRatio;
static float m_maxZoomRatio;
QPoint m_moveStartPos;
QRect m_moveStartGeometry;
int m_modelInitialHeight = 0;
QTimer *m_rotationTimer = nullptr;
int m_widthInPixels = 0;
int m_heightInPixels = 0;
QVector3D m_moveToPosition;
bool m_moveAndZoomByWindow = true;
bool m_enableCullFace = true;
void updateProjectionMatrix();
void normalizeAngle(int &angle);
public:
static int m_defaultXRotation;
static int m_defaultYRotation;
static int m_defaultZRotation;
static QVector3D m_defaultEyePosition;
};
#endif