Clang format.
Some checks failed
All Builds / Qtk (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), ubuntu-latest) (push) Failing after 23s
All Builds / Qtk-Library (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), ubuntu-latest) (push) Failing after 22s
All Builds / Qtk-Plugins (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), ubuntu-latest) (push) Failing after 20s
All Builds / Qtk-Assimp-Targets (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/, ubuntu-latest) (push) Failing after 18s
Linting / Tidy (push) Failing after 24s
Linting / Format (app) (push) Failing after 23s
Linting / Format (src) (push) Failing after 23s
All Builds / Qtk (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), macos-latest) (push) Has been cancelled
All Builds / Qtk (-DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG, , windows-latest) (push) Has been cancelled
All Builds / Qtk-Library (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), macos-latest) (push) Has been cancelled
All Builds / Qtk-Library (-DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG, , windows-latest) (push) Has been cancelled
All Builds / Qtk-Plugins (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), macos-latest) (push) Has been cancelled
All Builds / Qtk-Plugins (-DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG, , windows-latest) (push) Has been cancelled
All Builds / Qtk-Assimp-Targets (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/, macos-latest) (push) Has been cancelled
Some checks failed
All Builds / Qtk (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), ubuntu-latest) (push) Failing after 23s
All Builds / Qtk-Library (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), ubuntu-latest) (push) Failing after 22s
All Builds / Qtk-Plugins (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), ubuntu-latest) (push) Failing after 20s
All Builds / Qtk-Assimp-Targets (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/, ubuntu-latest) (push) Failing after 18s
Linting / Tidy (push) Failing after 24s
Linting / Format (app) (push) Failing after 23s
Linting / Format (src) (push) Failing after 23s
All Builds / Qtk (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), macos-latest) (push) Has been cancelled
All Builds / Qtk (-DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG, , windows-latest) (push) Has been cancelled
All Builds / Qtk-Library (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), macos-latest) (push) Has been cancelled
All Builds / Qtk-Library (-DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG, , windows-latest) (push) Has been cancelled
All Builds / Qtk-Plugins (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/ $CONFIG, -j $(nproc), macos-latest) (push) Has been cancelled
All Builds / Qtk-Plugins (-DCMAKE_PREFIX_PATH=D:/a/qtk/qtk/Qt/$QT_VERSION/mingw81_64/ $CONFIG, , windows-latest) (push) Has been cancelled
All Builds / Qtk-Assimp-Targets (-DCMAKE_PREFIX_PATH=/home/runner/work/qtk/Qt/$QT_VERSION/gcc_64/, macos-latest) (push) Has been cancelled
This commit is contained in:
@@ -15,10 +15,13 @@
|
||||
using namespace Qtk;
|
||||
|
||||
DebugConsole::DebugConsole(QWidget * owner, const QString & key) :
|
||||
DebugConsole(owner, key, key + "Debugger") {}
|
||||
DebugConsole(owner, key, key + "Debugger")
|
||||
{
|
||||
}
|
||||
|
||||
DebugConsole::DebugConsole(
|
||||
QWidget * owner, const QString & key, const QString & name) {
|
||||
DebugConsole::DebugConsole(QWidget * owner, const QString & key,
|
||||
const QString & name)
|
||||
{
|
||||
ui_ = new Ui::DebugConsole;
|
||||
ui_->setupUi(this);
|
||||
setObjectName(name);
|
||||
@@ -27,7 +30,7 @@ DebugConsole::DebugConsole(
|
||||
setWindowTitle(name + " Debug Console");
|
||||
|
||||
auto qtkWidget = dynamic_cast<QtkWidget *>(owner);
|
||||
if(qtkWidget) {
|
||||
if (qtkWidget) {
|
||||
connect(qtkWidget, &QtkWidget::sendLog, this, &DebugConsole::sendLog);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
#include "qtkwidget.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class DebugConsole;
|
||||
}
|
||||
|
||||
namespace Qtk {
|
||||
class DebugConsole : public QDockWidget {
|
||||
namespace Qtk
|
||||
{
|
||||
class DebugConsole : public QDockWidget
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
@@ -61,7 +64,8 @@ namespace Qtk {
|
||||
* @param context The DebugContext to use for the message.
|
||||
* Default value is Status.
|
||||
*/
|
||||
inline void sendLog(QString message, DebugContext context = Status) {
|
||||
inline void sendLog(QString message, DebugContext context = Status)
|
||||
{
|
||||
mConsole->setTextColor(logColor(context));
|
||||
mConsole->append(logPrefix(message, context));
|
||||
}
|
||||
@@ -72,7 +76,8 @@ namespace Qtk {
|
||||
*
|
||||
* @param name Base name for the DebugConsole window.
|
||||
*/
|
||||
inline void setTitle(const QString& name) {
|
||||
inline void setTitle(const QString & name)
|
||||
{
|
||||
setWindowTitle(name + " Debug Console");
|
||||
}
|
||||
|
||||
@@ -81,8 +86,9 @@ namespace Qtk {
|
||||
* @param context Log context severity level.
|
||||
* @return QColor corresponding with the message context.
|
||||
*/
|
||||
[[nodiscard]] QColor logColor(const DebugContext & context) const {
|
||||
switch(context) {
|
||||
[[nodiscard]] QColor logColor(const DebugContext & context) const
|
||||
{
|
||||
switch (context) {
|
||||
case Status:
|
||||
return Qt::GlobalColor::darkGray;
|
||||
case Debug:
|
||||
@@ -105,10 +111,11 @@ namespace Qtk {
|
||||
* @param context The log context severity level.
|
||||
* @return The log message prefixed with the DebugContext level.
|
||||
*/
|
||||
[[nodiscard]] QString logPrefix(
|
||||
QString & message, const DebugContext & context) {
|
||||
[[nodiscard]] QString logPrefix(QString & message,
|
||||
const DebugContext & context)
|
||||
{
|
||||
QString prefix;
|
||||
switch(context) {
|
||||
switch (context) {
|
||||
case Status:
|
||||
prefix = "[Status]: ";
|
||||
break;
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#include "qtkmainwindow.h"
|
||||
#include "qtkscene.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
Q_INIT_RESOURCE(resources);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
@@ -16,7 +16,8 @@ MainWindow * MainWindow::mainWindow_ = Q_NULLPTR;
|
||||
* Constructors / Destructors
|
||||
******************************************************************************/
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
||||
MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent)
|
||||
{
|
||||
ui_ = new Ui::MainWindow;
|
||||
setObjectName("MainWindow");
|
||||
// For use in design mode using Qt Creator
|
||||
@@ -26,7 +27,7 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
||||
|
||||
// Initialize static container for all active QtkWidgets
|
||||
auto qtkWidgets = findChildren<Qtk::QtkWidget *>();
|
||||
for(auto & qtkWidget : qtkWidgets) {
|
||||
for (auto & qtkWidget : qtkWidgets) {
|
||||
// Qtk currently uses the decorator pattern to save / load scenes.
|
||||
// This is a temporary solution and will be improved in the future.
|
||||
qtkWidget->setScene(new QtkScene);
|
||||
@@ -35,12 +36,10 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
||||
// Add GUI 'view' toolbar option to show debug console.
|
||||
ui_->menuView->addAction(qtkWidget->getActionToggleConsole());
|
||||
// Refresh GUI widgets when scene or objects are updated.
|
||||
connect(
|
||||
qtkWidget->getScene(), &Qtk::Scene::sceneUpdated, this,
|
||||
&MainWindow::refreshScene);
|
||||
connect(
|
||||
qtkWidget, &Qtk::QtkWidget::objectFocusChanged, ui_->qtk__ToolBox,
|
||||
&Qtk::ToolBox::updateFocus);
|
||||
connect(qtkWidget->getScene(), &Qtk::Scene::sceneUpdated, this,
|
||||
&MainWindow::refreshScene);
|
||||
connect(qtkWidget, &Qtk::QtkWidget::objectFocusChanged, ui_->qtk__ToolBox,
|
||||
&Qtk::ToolBox::updateFocus);
|
||||
}
|
||||
|
||||
// TODO: Fix / use MainWindow in Qt Designer to add these dock widgets.
|
||||
@@ -60,7 +59,8 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) {
|
||||
setWindowIcon(Qtk::getIcon());
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
@@ -68,15 +68,17 @@ MainWindow::~MainWindow() {
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
MainWindow * MainWindow::getMainWindow() {
|
||||
if(mainWindow_ == Q_NULLPTR) {
|
||||
MainWindow * MainWindow::getMainWindow()
|
||||
{
|
||||
if (mainWindow_ == Q_NULLPTR) {
|
||||
mainWindow_ = new MainWindow;
|
||||
}
|
||||
return mainWindow_;
|
||||
}
|
||||
|
||||
Qtk::QtkWidget * MainWindow::getQtkWidget(int64_t index) {
|
||||
if(views_.size() <= index) {
|
||||
Qtk::QtkWidget * MainWindow::getQtkWidget(int64_t index)
|
||||
{
|
||||
if (views_.size() <= index) {
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
auto it = views_.begin();
|
||||
@@ -84,14 +86,16 @@ Qtk::QtkWidget * MainWindow::getQtkWidget(int64_t index) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Qtk::QtkWidget * MainWindow::getQtkWidget(const QString & name) {
|
||||
if(!views_.count(name)) {
|
||||
Qtk::QtkWidget * MainWindow::getQtkWidget(const QString & name)
|
||||
{
|
||||
if (!views_.count(name)) {
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
return views_[name];
|
||||
}
|
||||
|
||||
void MainWindow::refreshScene(const QString & sceneName) {
|
||||
void MainWindow::refreshScene(const QString & sceneName)
|
||||
{
|
||||
// TODO: Select TreeView using sceneName
|
||||
ui_->qtk__TreeView->updateView(getQtkWidget()->getScene());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
#include "debugconsole.h"
|
||||
#include "qtkwidget.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
@@ -25,7 +26,8 @@ namespace Ui {
|
||||
* MainWindow class to provide an example of using a QtkWidget within a Qt
|
||||
* window application.
|
||||
*/
|
||||
class MainWindow : public QMainWindow {
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
@@ -14,13 +14,15 @@ using namespace Qtk;
|
||||
* Constructors, Destructors
|
||||
******************************************************************************/
|
||||
|
||||
QtkScene::QtkScene() {
|
||||
QtkScene::QtkScene()
|
||||
{
|
||||
setSceneName("Qtk Scene");
|
||||
getCamera().getTransform().setTranslation(0.0f, 0.0f, 20.0f);
|
||||
getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
QtkScene::~QtkScene() {
|
||||
QtkScene::~QtkScene()
|
||||
{
|
||||
delete mTestPhong;
|
||||
delete mTestSpecular;
|
||||
delete mTestDiffuse;
|
||||
@@ -31,7 +33,8 @@ QtkScene::~QtkScene() {
|
||||
* Public Member Functions
|
||||
******************************************************************************/
|
||||
|
||||
void QtkScene::init() {
|
||||
void QtkScene::init()
|
||||
{
|
||||
// Add a skybox to the scene using default cube map images and settings.
|
||||
setSkybox(new Qtk::Skybox("Skybox"));
|
||||
|
||||
@@ -116,8 +119,8 @@ void QtkScene::init() {
|
||||
// NOTE: You no longer need to manually bind shader program to set uniforms.
|
||||
// + You can still bind it if you want to for performance reasons.
|
||||
// + Qtk will only bind / release if the shader program is not already bound.
|
||||
mTestPhong->setShaders(
|
||||
":/shaders/solid-phong.vert", ":/shaders/solid-phong.frag");
|
||||
mTestPhong->setShaders(":/shaders/solid-phong.vert",
|
||||
":/shaders/solid-phong.frag");
|
||||
|
||||
// For example this would technically not be efficient, because each one of
|
||||
// these calls will bind, set, release. We could instead bind, set N uniforms,
|
||||
@@ -143,16 +146,16 @@ void QtkScene::init() {
|
||||
/* Example of a cube with no lighting applied */
|
||||
mesh = addObject(new Qtk::MeshRenderer("noLight", Cube(QTK_DRAW_ELEMENTS)));
|
||||
mesh->getTransform().setTranslation(5.0f, 0.0f, -2.0f);
|
||||
mesh->setShaders(
|
||||
":/shaders/solid-perspective.vert", ":/shaders/solid-perspective.frag");
|
||||
mesh->setShaders(":/shaders/solid-perspective.vert",
|
||||
":/shaders/solid-perspective.frag");
|
||||
mesh->setUniform("uColor", QVector3D(0.0f, 0.25f, 0.0f));
|
||||
// No light source needed for this lighting technique
|
||||
|
||||
/* Initialize Ambient example cube */
|
||||
mTestAmbient = new Qtk::MeshRenderer("ambient", Cube());
|
||||
mTestAmbient->getTransform().setTranslation(7.0f, 0.0f, -2.0f);
|
||||
mTestAmbient->setShaders(
|
||||
":/shaders/solid-ambient.vert", ":/shaders/solid-ambient.frag");
|
||||
mTestAmbient->setShaders(":/shaders/solid-ambient.vert",
|
||||
":/shaders/solid-ambient.frag");
|
||||
// Changing these uniform values will alter lighting effects.
|
||||
mTestAmbient->setUniform("uColor", QVector3D(0.0f, 0.25f, 0.0f));
|
||||
mTestAmbient->setUniform("uLightColor", QVector3D(1.0f, 1.0f, 1.0f));
|
||||
@@ -163,8 +166,8 @@ void QtkScene::init() {
|
||||
/* Initialize Diffuse example cube */
|
||||
mTestDiffuse = new Qtk::MeshRenderer("diffuse", Cube());
|
||||
mTestDiffuse->getTransform().setTranslation(9.0f, 0.0f, -2.0f);
|
||||
mTestDiffuse->setShaders(
|
||||
":/shaders/solid-diffuse.vert", ":/shaders/solid-diffuse.frag");
|
||||
mTestDiffuse->setShaders(":/shaders/solid-diffuse.vert",
|
||||
":/shaders/solid-diffuse.frag");
|
||||
mTestDiffuse->setUniform("uColor", QVector3D(0.0f, 0.25f, 0.0f));
|
||||
mTestDiffuse->setUniform("uLightColor", QVector3D(1.0f, 1.0f, 1.0f));
|
||||
mTestDiffuse->setUniform("uAmbientStrength", 0.2f);
|
||||
@@ -179,8 +182,8 @@ void QtkScene::init() {
|
||||
/* Initialize Specular example cube */
|
||||
mTestSpecular = new Qtk::MeshRenderer("specular", Cube());
|
||||
mTestSpecular->getTransform().setTranslation(11.0f, 0.0f, -2.0f);
|
||||
mTestSpecular->setShaders(
|
||||
":/shaders/solid-specular.vert", ":/shaders/solid-specular.frag");
|
||||
mTestSpecular->setShaders(":/shaders/solid-specular.vert",
|
||||
":/shaders/solid-specular.frag");
|
||||
mTestSpecular->setUniform("uColor", QVector3D(0.0f, 0.25f, 0.0f));
|
||||
mTestSpecular->setUniform("uLightColor", QVector3D(1.0f, 1.0f, 1.0f));
|
||||
mTestSpecular->setUniform("uAmbientStrength", 0.2f);
|
||||
@@ -246,8 +249,8 @@ void QtkScene::init() {
|
||||
model->setUniform("uLight.specular", QVector3D(1.0f, 1.0f, 1.0f));
|
||||
|
||||
// Light source for alienTest object.
|
||||
mesh = addObject(new Qtk::MeshRenderer(
|
||||
"alienTestLight", Triangle(Qtk::QTK_DRAW_ELEMENTS)));
|
||||
mesh = addObject(new Qtk::MeshRenderer("alienTestLight",
|
||||
Triangle(Qtk::QTK_DRAW_ELEMENTS)));
|
||||
mesh->getTransform().setTranslation(4.0f, 1.5f, 10.0f);
|
||||
mesh->getTransform().scale(0.25f);
|
||||
// This function changes values we have allocated in a buffer, so init() after
|
||||
@@ -290,8 +293,8 @@ void QtkScene::init() {
|
||||
mesh->reallocateNormals(mesh->getNormals());
|
||||
|
||||
// RGB Normals cube to show normals are correct with QTK_DRAW_ELEMENTS_NORMALS
|
||||
mesh = addObject(new Qtk::MeshRenderer(
|
||||
"rgbNormalsCubeElementsTest", Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh = addObject(new Qtk::MeshRenderer("rgbNormalsCubeElementsTest",
|
||||
Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh->getTransform().setTranslation(5.0f, 0.0f, 2.0f);
|
||||
mesh->setShaders(":/shaders/rgb-normals.vert", ":/shaders/rgb-normals.frag");
|
||||
mesh->reallocateNormals(mesh->getNormals());
|
||||
@@ -321,8 +324,8 @@ void QtkScene::init() {
|
||||
mesh->reallocateTexCoords(mesh->getTexCoords());
|
||||
|
||||
// Test drawing a cube with texture coordinates using glDrawElements
|
||||
mesh = addObject(new Qtk::MeshRenderer(
|
||||
"uvCubeElementsTest", Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh = addObject(new Qtk::MeshRenderer("uvCubeElementsTest",
|
||||
Cube(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh->getTransform().setTranslation(-1.7f, 0.0f, -2.0f);
|
||||
mesh->setTexture(":/textures/crate.png");
|
||||
mesh->setShaders(":/shaders/texture2d.vert", ":/shaders/texture2d.frag");
|
||||
@@ -339,8 +342,8 @@ void QtkScene::init() {
|
||||
addObject(new Qtk::MeshRenderer("testCubeMap", Cube(QTK_DRAW_ELEMENTS)));
|
||||
mesh->getTransform().setTranslation(-3.0f, 1.0f, -2.0f);
|
||||
mesh->getTransform().setRotation(45.0f, 0.0f, 1.0f, 0.0f);
|
||||
mesh->setShaders(
|
||||
":/shaders/texture-cubemap.vert", ":/shaders/texture-cubemap.frag");
|
||||
mesh->setShaders(":/shaders/texture-cubemap.vert",
|
||||
":/shaders/texture-cubemap.frag");
|
||||
mesh->setCubeMap(":/textures/crate.png");
|
||||
mesh->setUniform("uTexture", 0);
|
||||
mesh->reallocateTexCoords(mesh->getTexCoords());
|
||||
@@ -354,15 +357,15 @@ void QtkScene::init() {
|
||||
mesh->reallocateNormals(mesh->getNormals());
|
||||
|
||||
// RGB Normals triangle to show normals are correct with QTK_DRAW_ARRAYS
|
||||
mesh = addObject(new Qtk::MeshRenderer(
|
||||
"rgbTriangleArraysTest", Triangle(QTK_DRAW_ARRAYS)));
|
||||
mesh = addObject(new Qtk::MeshRenderer("rgbTriangleArraysTest",
|
||||
Triangle(QTK_DRAW_ARRAYS)));
|
||||
mesh->getTransform().setTranslation(7.0f, 0.0f, 2.0f);
|
||||
mesh->setShaders(":/shaders/rgb-normals.vert", ":/shaders/rgb-normals.frag");
|
||||
mesh->reallocateNormals(mesh->getNormals());
|
||||
|
||||
// RGB Normals triangle to show normals are correct with QTK_DRAW_ELEMENTS
|
||||
mesh = addObject(new Qtk::MeshRenderer(
|
||||
"rgbTriangleElementsTest", Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh = addObject(new Qtk::MeshRenderer("rgbTriangleElementsTest",
|
||||
Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh->getTransform().setTranslation(7.0f, 0.0f, 4.0f);
|
||||
mesh->setShaders(":/shaders/rgb-normals.vert", ":/shaders/rgb-normals.frag");
|
||||
mesh->reallocateNormals(mesh->getNormals());
|
||||
@@ -378,8 +381,8 @@ void QtkScene::init() {
|
||||
mesh->reallocateTexCoords(mesh->getTexCoords());
|
||||
|
||||
// Test drawing triangle with glDrawElements with texture coordinates
|
||||
mesh = addObject(new Qtk::MeshRenderer(
|
||||
"testTriangleElementsUV", Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh = addObject(new Qtk::MeshRenderer("testTriangleElementsUV",
|
||||
Triangle(QTK_DRAW_ELEMENTS_NORMALS)));
|
||||
mesh->getTransform().setTranslation(-2.5f, 0.0f, -1.0f);
|
||||
mesh->setShaders(":/shaders/texture2d.vert", ":/shaders/texture2d.frag");
|
||||
mesh->setTexture(":/textures/crate.png");
|
||||
@@ -387,20 +390,20 @@ void QtkScene::init() {
|
||||
mesh->reallocateTexCoords(mesh->getTexCoords());
|
||||
}
|
||||
|
||||
void QtkScene::draw() {
|
||||
void QtkScene::draw()
|
||||
{
|
||||
// WARNING: We must call the base class draw() function first.
|
||||
// + This will handle rendering core scene components like the Skybox.
|
||||
Scene::draw();
|
||||
|
||||
mTestPhong->bindShaders();
|
||||
mTestPhong->setUniform(
|
||||
"uModelInverseTransposed",
|
||||
mTestPhong->getTransform().toMatrix().normalMatrix());
|
||||
mTestPhong->setUniform("uModelInverseTransposed",
|
||||
mTestPhong->getTransform().toMatrix().normalMatrix());
|
||||
mTestPhong->setUniform(
|
||||
"uLightPosition",
|
||||
MeshRenderer::getInstance("phongLight")->getTransform().getTranslation());
|
||||
mTestPhong->setUniform(
|
||||
"uCameraPosition", QtkScene::getCamera().getTransform().getTranslation());
|
||||
mTestPhong->setUniform("uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
mTestPhong->releaseShaders();
|
||||
mTestPhong->draw();
|
||||
|
||||
@@ -414,10 +417,10 @@ void QtkScene::draw() {
|
||||
mTestDiffuse->setUniform(
|
||||
"uModelInverseTransposed",
|
||||
mTestDiffuse->getTransform().toMatrix().normalMatrix());
|
||||
mTestDiffuse->setUniform(
|
||||
"uLightPosition", MeshRenderer::getInstance("diffuseLight")
|
||||
->getTransform()
|
||||
.getTranslation());
|
||||
mTestDiffuse->setUniform("uLightPosition",
|
||||
MeshRenderer::getInstance("diffuseLight")
|
||||
->getTransform()
|
||||
.getTranslation());
|
||||
mTestDiffuse->setUniform(
|
||||
"uCameraPosition", QtkScene::getCamera().getTransform().getTranslation());
|
||||
mTestDiffuse->releaseShaders();
|
||||
@@ -427,17 +430,18 @@ void QtkScene::draw() {
|
||||
mTestSpecular->setUniform(
|
||||
"uModelInverseTransposed",
|
||||
mTestSpecular->getTransform().toMatrix().normalMatrix());
|
||||
mTestSpecular->setUniform(
|
||||
"uLightPosition", MeshRenderer::getInstance("specularLight")
|
||||
->getTransform()
|
||||
.getTranslation());
|
||||
mTestSpecular->setUniform("uLightPosition",
|
||||
MeshRenderer::getInstance("specularLight")
|
||||
->getTransform()
|
||||
.getTranslation());
|
||||
mTestSpecular->setUniform(
|
||||
"uCameraPosition", QtkScene::getCamera().getTransform().getTranslation());
|
||||
mTestSpecular->releaseShaders();
|
||||
mTestSpecular->draw();
|
||||
}
|
||||
|
||||
void QtkScene::update() {
|
||||
void QtkScene::update()
|
||||
{
|
||||
auto mySpartan = Model::getInstance("My spartan");
|
||||
mySpartan->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
@@ -449,8 +453,8 @@ void QtkScene::update() {
|
||||
.getTranslation();
|
||||
auto alien = Model::getInstance("alienTest");
|
||||
alien->setUniform("uLight.position", position);
|
||||
alien->setUniform(
|
||||
"uCameraPosition", QtkScene::getCamera().getTransform().getTranslation());
|
||||
alien->setUniform("uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
auto posMatrix = alien->getTransform().toMatrix();
|
||||
alien->setUniform("uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||
alien->setUniform("uMVP.model", posMatrix);
|
||||
@@ -463,8 +467,8 @@ void QtkScene::update() {
|
||||
.getTranslation();
|
||||
auto spartan = Model::getInstance("spartanTest");
|
||||
spartan->setUniform("uLight.position", position);
|
||||
spartan->setUniform(
|
||||
"uCameraPosition", QtkScene::getCamera().getTransform().getTranslation());
|
||||
spartan->setUniform("uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
posMatrix = spartan->getTransform().toMatrix();
|
||||
spartan->setUniform("uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||
spartan->setUniform("uMVP.model", posMatrix);
|
||||
@@ -478,8 +482,8 @@ void QtkScene::update() {
|
||||
position =
|
||||
MeshRenderer::getInstance("testLight")->getTransform().getTranslation();
|
||||
phong->setUniform("uLight.position", position);
|
||||
phong->setUniform(
|
||||
"uCameraPosition", QtkScene::getCamera().getTransform().getTranslation());
|
||||
phong->setUniform("uCameraPosition",
|
||||
QtkScene::getCamera().getTransform().getTranslation());
|
||||
posMatrix = phong->getTransform().toMatrix();
|
||||
phong->setUniform("uMVP.normalMatrix", posMatrix.normalMatrix());
|
||||
phong->setUniform("uMVP.model", posMatrix);
|
||||
@@ -489,8 +493,8 @@ void QtkScene::update() {
|
||||
|
||||
// Rotate lighting example cubes
|
||||
mTestPhong->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
MeshRenderer::getInstance("noLight")->getTransform().rotate(
|
||||
0.75f, 0.5f, 0.3f, 0.2f);
|
||||
MeshRenderer::getInstance("noLight")->getTransform().rotate(0.75f, 0.5f, 0.3f,
|
||||
0.2f);
|
||||
mTestAmbient->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestDiffuse->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
mTestSpecular->getTransform().rotate(0.75f, 0.5f, 0.3f, 0.2f);
|
||||
@@ -517,7 +521,7 @@ void QtkScene::update() {
|
||||
->getTransform()
|
||||
.getTranslation()
|
||||
.x();
|
||||
if(posX < limit || posX > limit + 4.0f) {
|
||||
if (posX < limit || posX > limit + 4.0f) {
|
||||
translateX = -translateX;
|
||||
}
|
||||
MeshRenderer::getInstance("topTriangle")
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
*
|
||||
* To create your own Scene from scratch see Qtk::Scene.
|
||||
*/
|
||||
class QtkScene : public Qtk::Scene {
|
||||
class QtkScene : public Qtk::Scene
|
||||
{
|
||||
public:
|
||||
/***************************************************************************
|
||||
* Contructors / Destructors
|
||||
|
||||
@@ -32,11 +32,14 @@ using namespace Qtk;
|
||||
QtkWidget::QtkWidget(QWidget * parent) : QtkWidget(parent, "QtkWidget") {}
|
||||
|
||||
QtkWidget::QtkWidget(QWidget * parent, const QString & name) :
|
||||
QtkWidget(parent, name, Q_NULLPTR) {}
|
||||
QtkWidget(parent, name, Q_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
QtkWidget::QtkWidget(QWidget * parent, const QString & name, Scene * scene) :
|
||||
QOpenGLWidget(parent), mDebugLogger(Q_NULLPTR),
|
||||
mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR) {
|
||||
mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
setScene(scene);
|
||||
setObjectName(name);
|
||||
@@ -54,7 +57,8 @@ QtkWidget::QtkWidget(QWidget * parent, const QString & name, Scene * scene) :
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
}
|
||||
|
||||
QtkWidget::~QtkWidget() {
|
||||
QtkWidget::~QtkWidget()
|
||||
{
|
||||
makeCurrent();
|
||||
teardownGL();
|
||||
}
|
||||
@@ -63,7 +67,8 @@ QtkWidget::~QtkWidget() {
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
QAction * QtkWidget::getActionToggleConsole() {
|
||||
QAction * QtkWidget::getActionToggleConsole()
|
||||
{
|
||||
auto action = new QAction(mScene->getSceneName() + " debug console");
|
||||
action->setCheckable(true);
|
||||
action->setChecked(mConsoleActive);
|
||||
@@ -72,7 +77,8 @@ QAction * QtkWidget::getActionToggleConsole() {
|
||||
return action;
|
||||
}
|
||||
|
||||
void QtkWidget::initializeGL() {
|
||||
void QtkWidget::initializeGL()
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
// Connect the frameSwapped signal to call the update() function
|
||||
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
|
||||
@@ -80,11 +86,10 @@ void QtkWidget::initializeGL() {
|
||||
toggleConsole();
|
||||
// Initialize OpenGL debug context
|
||||
mDebugLogger = new QOpenGLDebugLogger(this);
|
||||
if(mDebugLogger->initialize()) {
|
||||
if (mDebugLogger->initialize()) {
|
||||
qDebug() << "GL_DEBUG Debug Logger" << mDebugLogger << "\n";
|
||||
connect(
|
||||
mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this,
|
||||
SLOT(messageLogged(QOpenGLDebugMessage)));
|
||||
connect(mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this,
|
||||
SLOT(messageLogged(QOpenGLDebugMessage)));
|
||||
mDebugLogger->startLogging();
|
||||
}
|
||||
|
||||
@@ -101,38 +106,41 @@ void QtkWidget::initializeGL() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void QtkWidget::resizeGL(int width, int height) {
|
||||
void QtkWidget::resizeGL(int width, int height)
|
||||
{
|
||||
Scene::getProjectionMatrix().setToIdentity();
|
||||
Scene::getProjectionMatrix().perspective(
|
||||
45.0f, float(width) / float(height), 0.1f, 1000.0f);
|
||||
Scene::getProjectionMatrix().perspective(45.0f, float(width) / float(height),
|
||||
0.1f, 1000.0f);
|
||||
}
|
||||
|
||||
void QtkWidget::paintGL() {
|
||||
void QtkWidget::paintGL()
|
||||
{
|
||||
// Clear buffers and draw the scene if it is valid.
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
if(mScene != Q_NULLPTR) {
|
||||
if (mScene != Q_NULLPTR) {
|
||||
mScene->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::setScene(Scene * scene) {
|
||||
if(mScene != Q_NULLPTR) {
|
||||
void QtkWidget::setScene(Scene * scene)
|
||||
{
|
||||
if (mScene != Q_NULLPTR) {
|
||||
delete mScene;
|
||||
connect(
|
||||
scene, &Scene::sceneUpdated, MainWindow::getMainWindow(),
|
||||
&MainWindow::refreshScene);
|
||||
connect(scene, &Scene::sceneUpdated, MainWindow::getMainWindow(),
|
||||
&MainWindow::refreshScene);
|
||||
}
|
||||
|
||||
mScene = scene;
|
||||
if(mScene != Q_NULLPTR) {
|
||||
if (mScene != Q_NULLPTR) {
|
||||
mConsole->setTitle(mScene->getSceneName());
|
||||
} else {
|
||||
mConsole->setTitle("Null Scene");
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::toggleConsole() {
|
||||
if(mConsoleActive) {
|
||||
void QtkWidget::toggleConsole()
|
||||
{
|
||||
if (mConsoleActive) {
|
||||
mConsole->setHidden(true);
|
||||
mConsoleActive = false;
|
||||
} else {
|
||||
@@ -147,17 +155,19 @@ void QtkWidget::toggleConsole() {
|
||||
* Protected Methods
|
||||
******************************************************************************/
|
||||
|
||||
void QtkWidget::dragEnterEvent(QDragEnterEvent * event) {
|
||||
if(event->mimeData()->hasFormat("text/plain")) {
|
||||
void QtkWidget::dragEnterEvent(QDragEnterEvent * event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("text/plain")) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::dropEvent(QDropEvent * event) {
|
||||
void QtkWidget::dropEvent(QDropEvent * event)
|
||||
{
|
||||
mConsole->sendLog(event->mimeData()->text());
|
||||
auto urls = event->mimeData()->urls();
|
||||
if(!urls.isEmpty()) {
|
||||
if(urls.size() > 1) {
|
||||
if (!urls.isEmpty()) {
|
||||
if (urls.size() > 1) {
|
||||
qDebug() << "Cannot accept drop of multiple files.";
|
||||
event->ignore();
|
||||
return;
|
||||
@@ -165,7 +175,7 @@ void QtkWidget::dropEvent(QDropEvent * event) {
|
||||
|
||||
// TODO: Support other object types.
|
||||
auto url = urls.front();
|
||||
if(url.fileName().endsWith(".obj")) {
|
||||
if (url.fileName().endsWith(".obj")) {
|
||||
mScene->loadModel(url);
|
||||
event->acceptProposedAction();
|
||||
} else {
|
||||
@@ -175,8 +185,9 @@ void QtkWidget::dropEvent(QDropEvent * event) {
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::keyPressEvent(QKeyEvent * event) {
|
||||
if(event->isAutoRepeat()) {
|
||||
void QtkWidget::keyPressEvent(QKeyEvent * event)
|
||||
{
|
||||
if (event->isAutoRepeat()) {
|
||||
// Do not repeat input while a key is held down
|
||||
event->ignore();
|
||||
} else {
|
||||
@@ -184,38 +195,43 @@ void QtkWidget::keyPressEvent(QKeyEvent * event) {
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::keyReleaseEvent(QKeyEvent * event) {
|
||||
if(event->isAutoRepeat()) {
|
||||
void QtkWidget::keyReleaseEvent(QKeyEvent * event)
|
||||
{
|
||||
if (event->isAutoRepeat()) {
|
||||
event->ignore();
|
||||
} else {
|
||||
Input::registerKeyRelease(event->key());
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::mousePressEvent(QMouseEvent * event) {
|
||||
void QtkWidget::mousePressEvent(QMouseEvent * event)
|
||||
{
|
||||
Input::registerMousePress(event->button());
|
||||
}
|
||||
|
||||
void QtkWidget::mouseReleaseEvent(QMouseEvent * event) {
|
||||
void QtkWidget::mouseReleaseEvent(QMouseEvent * event)
|
||||
{
|
||||
Input::registerMouseRelease(event->button());
|
||||
}
|
||||
|
||||
void QtkWidget::update() {
|
||||
void QtkWidget::update()
|
||||
{
|
||||
updateCameraInput();
|
||||
|
||||
if(mScene != Q_NULLPTR) {
|
||||
if (mScene != Q_NULLPTR) {
|
||||
mScene->update();
|
||||
}
|
||||
|
||||
QWidget::update();
|
||||
}
|
||||
|
||||
void QtkWidget::messageLogged(const QOpenGLDebugMessage & msg) {
|
||||
void QtkWidget::messageLogged(const QOpenGLDebugMessage & msg)
|
||||
{
|
||||
QString error;
|
||||
|
||||
DebugContext context;
|
||||
// Format based on severity
|
||||
switch(msg.severity()) {
|
||||
switch (msg.severity()) {
|
||||
case QOpenGLDebugMessage::NotificationSeverity:
|
||||
error += "--";
|
||||
context = Status;
|
||||
@@ -241,7 +257,7 @@ void QtkWidget::messageLogged(const QOpenGLDebugMessage & msg) {
|
||||
case QOpenGLDebugMessage::c: \
|
||||
error += #c; \
|
||||
break
|
||||
switch(msg.source()) {
|
||||
switch (msg.source()) {
|
||||
CASE(APISource);
|
||||
CASE(WindowSystemSource);
|
||||
CASE(ShaderCompilerSource);
|
||||
@@ -259,7 +275,7 @@ void QtkWidget::messageLogged(const QOpenGLDebugMessage & msg) {
|
||||
case QOpenGLDebugMessage::c: \
|
||||
error += #c; \
|
||||
break
|
||||
switch(msg.type()) {
|
||||
switch (msg.type()) {
|
||||
CASE(InvalidType);
|
||||
CASE(ErrorType);
|
||||
CASE(DeprecatedBehaviorType);
|
||||
@@ -282,14 +298,16 @@ void QtkWidget::messageLogged(const QOpenGLDebugMessage & msg) {
|
||||
* Private Methods
|
||||
******************************************************************************/
|
||||
|
||||
void QtkWidget::teardownGL() { /* Nothing to teardown yet... */
|
||||
void QtkWidget::teardownGL()
|
||||
{ /* Nothing to teardown yet... */
|
||||
}
|
||||
|
||||
void QtkWidget::updateCameraInput() {
|
||||
void QtkWidget::updateCameraInput()
|
||||
{
|
||||
Input::update();
|
||||
// Camera Transformation
|
||||
if(Input::buttonPressed(Qt::LeftButton)
|
||||
|| Input::buttonPressed(Qt::RightButton)) {
|
||||
if (Input::buttonPressed(Qt::LeftButton)
|
||||
|| Input::buttonPressed(Qt::RightButton)) {
|
||||
static const float transSpeed = 0.1f;
|
||||
static const float rotSpeed = 0.5f;
|
||||
|
||||
@@ -301,29 +319,30 @@ void QtkWidget::updateCameraInput() {
|
||||
|
||||
// Handle translations
|
||||
QVector3D translation;
|
||||
if(Input::keyPressed(Qt::Key_W)) {
|
||||
if (Input::keyPressed(Qt::Key_W)) {
|
||||
translation += Scene::getCamera().getForward();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_S)) {
|
||||
if (Input::keyPressed(Qt::Key_S)) {
|
||||
translation -= Scene::getCamera().getForward();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_A)) {
|
||||
if (Input::keyPressed(Qt::Key_A)) {
|
||||
translation -= Scene::getCamera().getRight();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_D)) {
|
||||
if (Input::keyPressed(Qt::Key_D)) {
|
||||
translation += Scene::getCamera().getRight();
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_Q)) {
|
||||
if (Input::keyPressed(Qt::Key_Q)) {
|
||||
translation -= Scene::getCamera().getUp() / 2.0f;
|
||||
}
|
||||
if(Input::keyPressed(Qt::Key_E)) {
|
||||
if (Input::keyPressed(Qt::Key_E)) {
|
||||
translation += Scene::getCamera().getUp() / 2.0f;
|
||||
}
|
||||
Scene::getCamera().getTransform().translate(transSpeed * translation);
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::printContextInformation() {
|
||||
void QtkWidget::printContextInformation()
|
||||
{
|
||||
QString glType;
|
||||
QString glVersion;
|
||||
QString glProfile;
|
||||
@@ -342,7 +361,7 @@ void QtkWidget::printContextInformation() {
|
||||
case QSurfaceFormat::c: \
|
||||
glProfile = #c; \
|
||||
break
|
||||
switch(format().profile()) {
|
||||
switch (format().profile()) {
|
||||
CASE(NoProfile);
|
||||
CASE(CoreProfile);
|
||||
CASE(CompatibilityProfile);
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#include <qtk/qtkapi.h>
|
||||
#include <qtk/scene.h>
|
||||
|
||||
namespace Qtk {
|
||||
namespace Qtk
|
||||
{
|
||||
class DebugConsole;
|
||||
|
||||
/**
|
||||
@@ -29,7 +30,8 @@ namespace Qtk {
|
||||
* This object has a Scene attached which manages the objects to render.
|
||||
* Client input is passed through this widget to control the camera view.
|
||||
*/
|
||||
class QtkWidget : public QOpenGLWidget, protected QOpenGLFunctions {
|
||||
class QtkWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
@@ -103,7 +105,8 @@ namespace Qtk {
|
||||
/**
|
||||
* @return Pointer to the QOpenGLDebugLogger attached to this widget.
|
||||
*/
|
||||
inline QOpenGLDebugLogger * getOpenGLDebugLogger() {
|
||||
inline QOpenGLDebugLogger * getOpenGLDebugLogger()
|
||||
{
|
||||
return mDebugLogger;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,34 +16,39 @@
|
||||
|
||||
using namespace Qtk;
|
||||
|
||||
ToolBox::ToolBox(QWidget * parent) : QDockWidget(parent), ui(new Ui::ToolBox) {
|
||||
ToolBox::ToolBox(QWidget * parent) : QDockWidget(parent), ui(new Ui::ToolBox)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setMinimumWidth(350);
|
||||
}
|
||||
|
||||
void ToolBox::updateFocus(const QString & name) {
|
||||
void ToolBox::updateFocus(const QString & name)
|
||||
{
|
||||
auto object =
|
||||
MainWindow::getMainWindow()->getQtkWidget()->getScene()->getObject(name);
|
||||
if(object != Q_NULLPTR) {
|
||||
if (object != Q_NULLPTR) {
|
||||
removePages();
|
||||
createPageProperties(object);
|
||||
createPageShader(object);
|
||||
}
|
||||
}
|
||||
|
||||
ToolBox::~ToolBox() {
|
||||
ToolBox::~ToolBox()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ToolBox::removePages() {
|
||||
void ToolBox::removePages()
|
||||
{
|
||||
// Remove all existing pages.
|
||||
for(size_t i = 0; i < ui->toolBox->count(); i++) {
|
||||
for (size_t i = 0; i < ui->toolBox->count(); i++) {
|
||||
delete ui->toolBox->widget(i);
|
||||
ui->toolBox->removeItem(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ToolBox::createPageProperties(const Object * object) {
|
||||
void ToolBox::createPageProperties(const Object * object)
|
||||
{
|
||||
auto transform = object->getTransform();
|
||||
auto type = object->getType();
|
||||
auto * widget = new QWidget;
|
||||
@@ -51,17 +56,16 @@ void ToolBox::createPageProperties(const Object * object) {
|
||||
ui->toolBox->setCurrentWidget(widget);
|
||||
|
||||
auto * layout = new QFormLayout;
|
||||
layout->addRow(
|
||||
new QLabel(tr("Name:")), new QLabel(object->getName().c_str()));
|
||||
layout->addRow(new QLabel(tr("Name:")),
|
||||
new QLabel(object->getName().c_str()));
|
||||
|
||||
layout->addRow(
|
||||
new QLabel(tr("Type:")),
|
||||
new QLabel(type == Object::Type::QTK_MESH ? "Mesh" : "Model"));
|
||||
layout->addRow(new QLabel(tr("Type:")),
|
||||
new QLabel(type == Object::Type::QTK_MESH ? "Mesh" : "Model"));
|
||||
|
||||
auto rowLayout = new QHBoxLayout;
|
||||
rowLayout->addWidget(new QLabel(tr("Translation:")));
|
||||
int minWidth = 75;
|
||||
for(size_t i = 0; i < 3; i++) {
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
auto spinBox = new QDoubleSpinBox;
|
||||
spinBox->setMinimum(std::numeric_limits<double>::lowest());
|
||||
spinBox->setSingleStep(0.1);
|
||||
@@ -69,25 +73,22 @@ void ToolBox::createPageProperties(const Object * object) {
|
||||
spinBox->setFixedWidth(minWidth);
|
||||
rowLayout->addWidget(spinBox);
|
||||
|
||||
if(i == 0) {
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setTranslationX);
|
||||
} else if(i == 1) {
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setTranslationY);
|
||||
} else if(i == 2) {
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setTranslationZ);
|
||||
if (i == 0) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setTranslationX);
|
||||
} else if (i == 1) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setTranslationY);
|
||||
} else if (i == 2) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setTranslationZ);
|
||||
}
|
||||
}
|
||||
layout->addRow(rowLayout);
|
||||
|
||||
rowLayout = new QHBoxLayout;
|
||||
rowLayout->addWidget(new QLabel(tr("Scale:")));
|
||||
for(size_t i = 0; i < 3; i++) {
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
auto spinBox = new QDoubleSpinBox;
|
||||
spinBox->setMinimum(std::numeric_limits<double>::lowest());
|
||||
spinBox->setSingleStep(0.1);
|
||||
@@ -95,22 +96,23 @@ void ToolBox::createPageProperties(const Object * object) {
|
||||
spinBox->setFixedWidth(minWidth);
|
||||
rowLayout->addWidget(spinBox);
|
||||
|
||||
if(i == 0) {
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object, &Object::setScaleX);
|
||||
} else if(i == 1) {
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object, &Object::setScaleY);
|
||||
} else if(i == 2) {
|
||||
connect(
|
||||
spinBox, &QDoubleSpinBox::valueChanged, object, &Object::setScaleZ);
|
||||
if (i == 0) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setScaleX);
|
||||
} else if (i == 1) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setScaleY);
|
||||
} else if (i == 2) {
|
||||
connect(spinBox, &QDoubleSpinBox::valueChanged, object,
|
||||
&Object::setScaleZ);
|
||||
}
|
||||
}
|
||||
layout->addRow(rowLayout);
|
||||
widget->setLayout(layout);
|
||||
}
|
||||
|
||||
void ToolBox::createPageShader(const Object * object) {
|
||||
void ToolBox::createPageShader(const Object * object)
|
||||
{
|
||||
// Shaders page.
|
||||
auto widget = new QWidget;
|
||||
ui->toolBox->addItem(widget, "Shaders");
|
||||
@@ -123,7 +125,7 @@ void ToolBox::createPageShader(const Object * object) {
|
||||
auto shaderView = new QTextEdit;
|
||||
shaderView->setReadOnly(true);
|
||||
auto vertexFile = QFile(object->getVertexShader().c_str());
|
||||
if(vertexFile.exists()) {
|
||||
if (vertexFile.exists()) {
|
||||
vertexFile.open(QIODeviceBase::ReadOnly);
|
||||
shaderView->setText(vertexFile.readAll());
|
||||
vertexFile.close();
|
||||
@@ -138,7 +140,7 @@ void ToolBox::createPageShader(const Object * object) {
|
||||
shaderView = new QTextEdit;
|
||||
shaderView->setReadOnly(true);
|
||||
auto fragmentfile = QFile(object->getFragmentShader().c_str());
|
||||
if(fragmentfile.exists()) {
|
||||
if (fragmentfile.exists()) {
|
||||
fragmentfile.open(QIODeviceBase::ReadOnly);
|
||||
shaderView->setText(fragmentfile.readAll());
|
||||
fragmentfile.close();
|
||||
|
||||
@@ -18,12 +18,15 @@
|
||||
|
||||
#include "qtk/scene.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class ToolBox;
|
||||
}
|
||||
|
||||
namespace Qtk {
|
||||
class ToolBox : public QDockWidget {
|
||||
namespace Qtk
|
||||
{
|
||||
class ToolBox : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
@@ -16,14 +16,15 @@
|
||||
******************************************************************************/
|
||||
|
||||
Qtk::TreeView::TreeView(QWidget * parent) :
|
||||
QDockWidget(parent), ui(new Ui::TreeView) {
|
||||
QDockWidget(parent), ui(new Ui::TreeView)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(
|
||||
ui->treeWidget, &QTreeWidget::itemDoubleClicked, this,
|
||||
&TreeView::itemFocus);
|
||||
connect(ui->treeWidget, &QTreeWidget::itemDoubleClicked, this,
|
||||
&TreeView::itemFocus);
|
||||
}
|
||||
|
||||
Qtk::TreeView::~TreeView() {
|
||||
Qtk::TreeView::~TreeView()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@@ -31,31 +32,33 @@ Qtk::TreeView::~TreeView() {
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
void Qtk::TreeView::updateView(const Qtk::Scene * scene) {
|
||||
void Qtk::TreeView::updateView(const Qtk::Scene * scene)
|
||||
{
|
||||
ui->treeWidget->clear();
|
||||
ui->treeWidget->setColumnCount(1);
|
||||
mSceneName = scene->getSceneName();
|
||||
auto objects = scene->getObjects();
|
||||
for(const auto & object : objects) {
|
||||
for (const auto & object : objects) {
|
||||
auto item =
|
||||
new QTreeWidgetItem(QStringList(QString(object->getName().c_str())));
|
||||
ui->treeWidget->insertTopLevelItem(0, item);
|
||||
}
|
||||
}
|
||||
|
||||
void Qtk::TreeView::itemFocus(QTreeWidgetItem * item, int column) {
|
||||
void Qtk::TreeView::itemFocus(QTreeWidgetItem * item, int column)
|
||||
{
|
||||
QString name = item->text(column);
|
||||
auto scene = MainWindow::getMainWindow()->getQtkWidget()->getScene();
|
||||
auto & transform = Qtk::Scene::getCamera().getTransform();
|
||||
auto object = scene->getObject(name);
|
||||
Transform3D * objectTransform;
|
||||
// If the object is a mesh or model, focus the camera on it.
|
||||
if(object == Q_NULLPTR) {
|
||||
if (object == Q_NULLPTR) {
|
||||
qDebug() << "Attempt to get non-existing object with name '" << name
|
||||
<< "'\n";
|
||||
} else if(object->getType() == Object::QTK_MESH) {
|
||||
} else if (object->getType() == Object::QTK_MESH) {
|
||||
objectTransform = &dynamic_cast<MeshRenderer *>(object)->getTransform();
|
||||
} else if(object->getType() == Object::QTK_MODEL) {
|
||||
} else if (object->getType() == Object::QTK_MODEL) {
|
||||
objectTransform = &dynamic_cast<Model *>(object)->getTransform();
|
||||
}
|
||||
auto focusScale = objectTransform->getScale();
|
||||
@@ -68,5 +71,5 @@ void Qtk::TreeView::itemFocus(QTreeWidgetItem * item, int column) {
|
||||
transform.translate(0.0f, 0.0f, 3.0f);
|
||||
|
||||
// Emit signal from qtk widget for new object focus. Triggers GUI updates.
|
||||
emit MainWindow::getMainWindow()->getQtkWidget()->objectFocusChanged(name);
|
||||
emit MainWindow::getMainWindow() -> getQtkWidget()->objectFocusChanged(name);
|
||||
}
|
||||
|
||||
@@ -17,12 +17,15 @@
|
||||
#include <qtk/scene.h>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class TreeView;
|
||||
}
|
||||
|
||||
namespace Qtk {
|
||||
class TreeView : public QDockWidget {
|
||||
namespace Qtk
|
||||
{
|
||||
class TreeView : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
* Constructors, Destructors
|
||||
******************************************************************************/
|
||||
|
||||
WidgetPlugin::WidgetPlugin(
|
||||
QString group, QString class_name, QString include,
|
||||
WidgetPlugin::Factory factory) :
|
||||
m_group(std::move(group)),
|
||||
m_className(std::move(class_name)), m_includeFile(std::move(include)),
|
||||
m_factory(std::move(factory)), m_objectName(m_className) {}
|
||||
WidgetPlugin::WidgetPlugin(QString group, QString class_name, QString include,
|
||||
WidgetPlugin::Factory factory) :
|
||||
m_group(std::move(group)), m_className(std::move(class_name)),
|
||||
m_includeFile(std::move(include)), m_factory(std::move(factory)),
|
||||
m_objectName(m_className)
|
||||
{
|
||||
}
|
||||
|
||||
WidgetPlugin::WidgetPlugin(QObject * parent) : QObject(parent) {}
|
||||
|
||||
@@ -32,50 +33,61 @@ WidgetPlugin::WidgetPlugin(QObject * parent) : QObject(parent) {}
|
||||
* Public Methods
|
||||
******************************************************************************/
|
||||
|
||||
QString WidgetPlugin::group() const {
|
||||
QString WidgetPlugin::group() const
|
||||
{
|
||||
return m_group;
|
||||
}
|
||||
|
||||
QString WidgetPlugin::name() const {
|
||||
QString WidgetPlugin::name() const
|
||||
{
|
||||
return m_className;
|
||||
}
|
||||
|
||||
QString WidgetPlugin::includeFile() const {
|
||||
QString WidgetPlugin::includeFile() const
|
||||
{
|
||||
return m_includeFile;
|
||||
}
|
||||
|
||||
QWidget * WidgetPlugin::createWidget(QWidget * parent) {
|
||||
QWidget * WidgetPlugin::createWidget(QWidget * parent)
|
||||
{
|
||||
return m_factory(parent);
|
||||
}
|
||||
|
||||
QString WidgetPlugin::toolTip() const {
|
||||
QString WidgetPlugin::toolTip() const
|
||||
{
|
||||
return QStringLiteral("A custom widget tool tip.");
|
||||
}
|
||||
|
||||
QString WidgetPlugin::whatsThis() const {
|
||||
QString WidgetPlugin::whatsThis() const
|
||||
{
|
||||
return QStringLiteral("Custom widget what's this?");
|
||||
}
|
||||
|
||||
QIcon WidgetPlugin::icon() const {
|
||||
QIcon WidgetPlugin::icon() const
|
||||
{
|
||||
return Qtk::getIcon();
|
||||
}
|
||||
|
||||
bool WidgetPlugin::isContainer() const {
|
||||
bool WidgetPlugin::isContainer() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WidgetPlugin::isInitialized() const {
|
||||
bool WidgetPlugin::isInitialized() const
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
void WidgetPlugin::initialize(QDesignerFormEditorInterface *) {
|
||||
if(m_initialized) {
|
||||
void WidgetPlugin::initialize(QDesignerFormEditorInterface *)
|
||||
{
|
||||
if (m_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
QString WidgetPlugin::domXml() const {
|
||||
QString WidgetPlugin::domXml() const
|
||||
{
|
||||
return
|
||||
"<ui language=\"c++\">\n"
|
||||
" <widget class=\"" + m_className + "\" name=\"" + m_objectName + "\">\n"
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
|
||||
class QDESIGNER_WIDGET_EXPORT WidgetPlugin :
|
||||
public QObject,
|
||||
public QDesignerCustomWidgetInterface {
|
||||
public QDesignerCustomWidgetInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -26,8 +27,8 @@ class QDESIGNER_WIDGET_EXPORT WidgetPlugin :
|
||||
* Contructors / Destructors
|
||||
**************************************************************************/
|
||||
|
||||
WidgetPlugin(
|
||||
QString group, QString class_name, QString include, Factory factory);
|
||||
WidgetPlugin(QString group, QString class_name, QString include,
|
||||
Factory factory);
|
||||
|
||||
explicit WidgetPlugin(QObject * parent = nullptr);
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
******************************************************************************/
|
||||
|
||||
WidgetPluginCollection::WidgetPluginCollection(QObject * parent) :
|
||||
QObject(parent), m_collectionName("Qtk Widget Collection") {
|
||||
QObject(parent), m_collectionName("Qtk Widget Collection")
|
||||
{
|
||||
m_collection = {
|
||||
new WidgetPlugin(
|
||||
m_collectionName, "Qtk::QtkWidget", "qtkwidget.h",
|
||||
@@ -38,6 +39,7 @@ WidgetPluginCollection::WidgetPluginCollection(QObject * parent) :
|
||||
******************************************************************************/
|
||||
|
||||
QList<QDesignerCustomWidgetInterface *> WidgetPluginCollection::customWidgets()
|
||||
const {
|
||||
const
|
||||
{
|
||||
return m_collection;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
class WidgetPluginCollection :
|
||||
public QObject,
|
||||
public QDesignerCustomWidgetCollectionInterface {
|
||||
public QDesignerCustomWidgetCollectionInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
// Since we're exporting a collection, this is the only plugin metadata
|
||||
// needed. We don't need this for-each widget in the collection.
|
||||
@@ -36,7 +37,8 @@ class WidgetPluginCollection :
|
||||
/**
|
||||
* @return QList of all custom widgets pointers.
|
||||
*/
|
||||
[[nodiscard]] QList<QDesignerCustomWidgetInterface *> customWidgets() const override;
|
||||
[[nodiscard]] QList<QDesignerCustomWidgetInterface *> customWidgets()
|
||||
const override;
|
||||
|
||||
private:
|
||||
/***************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user