2018-03-11 03:18:24 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QToolBar>
|
2018-03-11 16:02:15 +00:00
|
|
|
#include <QThread>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "skeletoneditwidget.h"
|
|
|
|
#include "meshlite.h"
|
|
|
|
#include "skeletontomesh.h"
|
2018-03-10 06:57:14 +00:00
|
|
|
|
2018-03-12 05:27:22 +00:00
|
|
|
MainWindow::MainWindow() :
|
|
|
|
m_skeletonToMesh(NULL),
|
|
|
|
m_skeletonDirty(false)
|
2018-03-10 06:57:14 +00:00
|
|
|
{
|
2018-03-11 03:18:24 +00:00
|
|
|
QPushButton *skeletonButton = new QPushButton("Skeleton");
|
|
|
|
QPushButton *motionButton = new QPushButton("Motion");
|
|
|
|
QPushButton *modelButton = new QPushButton("Model");
|
|
|
|
|
|
|
|
QButtonGroup *pageButtonGroup = new QButtonGroup;
|
|
|
|
pageButtonGroup->addButton(skeletonButton);
|
|
|
|
pageButtonGroup->addButton(motionButton);
|
|
|
|
pageButtonGroup->addButton(modelButton);
|
|
|
|
|
|
|
|
skeletonButton->setCheckable(true);
|
|
|
|
motionButton->setCheckable(true);
|
|
|
|
modelButton->setCheckable(true);
|
|
|
|
|
|
|
|
pageButtonGroup->setExclusive(true);
|
|
|
|
|
|
|
|
skeletonButton->setChecked(true);
|
|
|
|
|
|
|
|
QHBoxLayout *topLayout = new QHBoxLayout;
|
|
|
|
topLayout->addStretch();
|
|
|
|
topLayout->addWidget(skeletonButton);
|
|
|
|
topLayout->addWidget(motionButton);
|
|
|
|
topLayout->addWidget(modelButton);
|
|
|
|
topLayout->addStretch();
|
|
|
|
|
|
|
|
skeletonButton->adjustSize();
|
|
|
|
motionButton->adjustSize();
|
|
|
|
modelButton->adjustSize();
|
|
|
|
|
2018-03-11 16:02:15 +00:00
|
|
|
m_skeletonEditWidget = new SkeletonEditWidget;
|
|
|
|
|
|
|
|
m_modelingWidget = new ModelingWidget;
|
|
|
|
m_modelingWidget->setFixedSize(128, 128);
|
2018-03-11 03:18:24 +00:00
|
|
|
|
|
|
|
QPushButton *changeTurnaroundButton = new QPushButton("Change turnaround..");
|
|
|
|
|
|
|
|
QVBoxLayout *rightLayout = new QVBoxLayout;
|
2018-03-11 16:02:15 +00:00
|
|
|
rightLayout->addWidget(m_modelingWidget);
|
2018-03-11 03:18:24 +00:00
|
|
|
rightLayout->addSpacing(10);
|
|
|
|
rightLayout->addWidget(changeTurnaroundButton);
|
|
|
|
rightLayout->addStretch();
|
|
|
|
|
|
|
|
QToolBar *toolbar = new QToolBar;
|
|
|
|
toolbar->setOrientation(Qt::Vertical);
|
|
|
|
QAction *addAction = new QAction(tr("Add"), this);
|
|
|
|
QAction *selectAction = new QAction(tr("Select"), this);
|
|
|
|
toolbar->addAction(addAction);
|
|
|
|
toolbar->addAction(selectAction);
|
|
|
|
|
|
|
|
QVBoxLayout *leftLayout = new QVBoxLayout;
|
|
|
|
leftLayout->addWidget(toolbar);
|
|
|
|
leftLayout->addStretch();
|
|
|
|
|
|
|
|
QHBoxLayout *middleLayout = new QHBoxLayout;
|
|
|
|
middleLayout->addLayout(leftLayout);
|
2018-03-11 16:02:15 +00:00
|
|
|
middleLayout->addWidget(m_skeletonEditWidget);
|
2018-03-11 03:18:24 +00:00
|
|
|
middleLayout->addLayout(rightLayout);
|
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
mainLayout->addLayout(topLayout);
|
|
|
|
mainLayout->addSpacing(20);
|
|
|
|
mainLayout->addLayout(middleLayout);
|
|
|
|
|
|
|
|
QWidget *centralWidget = new QWidget;
|
|
|
|
centralWidget->setLayout(mainLayout);
|
|
|
|
|
|
|
|
setCentralWidget(centralWidget);
|
|
|
|
setWindowTitle(tr("Dust 3D"));
|
2018-03-11 16:02:15 +00:00
|
|
|
|
|
|
|
bool connectResult;
|
|
|
|
|
|
|
|
connectResult = connect(addAction, SIGNAL(triggered(bool)), m_skeletonEditWidget->graphicsView(), SLOT(turnOnAddNodeMode()));
|
|
|
|
assert(connectResult);
|
|
|
|
|
|
|
|
connectResult = connectResult = connect(selectAction, SIGNAL(triggered(bool)), m_skeletonEditWidget->graphicsView(), SLOT(turnOffAddNodeMode()));
|
|
|
|
assert(connectResult);
|
|
|
|
|
|
|
|
connectResult = connect(m_skeletonEditWidget->graphicsView(), SIGNAL(nodesChanged()), this, SLOT(skeletonChanged()));
|
|
|
|
assert(connectResult);
|
2018-03-10 06:57:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-11 16:02:15 +00:00
|
|
|
void MainWindow::meshReady()
|
|
|
|
{
|
2018-03-12 05:27:22 +00:00
|
|
|
m_modelingWidget->updateMesh(m_skeletonToMesh->takeResultMesh());
|
|
|
|
delete m_skeletonToMesh;
|
|
|
|
m_skeletonToMesh = NULL;
|
|
|
|
if (m_skeletonDirty) {
|
|
|
|
skeletonChanged();
|
2018-03-11 16:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::skeletonChanged()
|
|
|
|
{
|
2018-03-12 05:27:22 +00:00
|
|
|
if (m_skeletonToMesh) {
|
|
|
|
m_skeletonDirty = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_skeletonDirty = false;
|
|
|
|
|
2018-03-11 16:02:15 +00:00
|
|
|
QThread *thread = new QThread;
|
2018-03-12 05:27:22 +00:00
|
|
|
m_skeletonToMesh = new SkeletonToMesh(m_skeletonEditWidget->graphicsView());
|
|
|
|
m_skeletonToMesh->moveToThread(thread);
|
|
|
|
connect(thread, SIGNAL(started()), m_skeletonToMesh, SLOT(process()));
|
|
|
|
connect(m_skeletonToMesh, SIGNAL(finished()), this, SLOT(meshReady()));
|
|
|
|
connect(m_skeletonToMesh, SIGNAL(finished()), thread, SLOT(quit()));
|
2018-03-11 16:02:15 +00:00
|
|
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
|
|
|
thread->start();
|
|
|
|
}
|