Add trival control of radius

master
Jeremy Hu 2018-03-28 19:41:33 +08:00
parent 09d21e8935
commit 64ce4e6843
3 changed files with 22 additions and 15 deletions

View File

@ -138,10 +138,8 @@ MainWindow::MainWindow()
saveAct->setStatusTip(tr("Save the document to disk")); saveAct->setStatusTip(tr("Save the document to disk"));
connect(saveAct, &QAction::triggered, this, &MainWindow::save); connect(saveAct, &QAction::triggered, this, &MainWindow::save);
QAction *exitAct = new QAction(tr("E&xit"), this); QAction *exportAct = new QAction(tr("E&xport.."), this);
exitAct->setShortcuts(QKeySequence::Quit); connect(exportAct, &QAction::triggered, this, &MainWindow::exportModel);
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, &QAction::triggered, this, &QWidget::close);
QAction *undoAct = new QAction(tr("&Undo"), this); QAction *undoAct = new QAction(tr("&Undo"), this);
undoAct->setShortcuts(QKeySequence::Undo); undoAct->setShortcuts(QKeySequence::Undo);
@ -179,7 +177,7 @@ MainWindow::MainWindow()
fileMenu->addAction(openAct); fileMenu->addAction(openAct);
fileMenu->addAction(saveAct); fileMenu->addAction(saveAct);
fileMenu->addSeparator(); fileMenu->addSeparator();
fileMenu->addAction(exitAct); fileMenu->addAction(exportAct);
QMenu *editMenu = menuBar()->addMenu(tr("&Edit")); QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(undoAct); editMenu->addAction(undoAct);

View File

@ -2,6 +2,7 @@
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QFile> #include <QFile>
#include <QApplication> #include <QApplication>
#include <QGuiApplication>
#include <cmath> #include <cmath>
#include <map> #include <map>
#include <vector> #include <vector>
@ -152,6 +153,7 @@ void SkeletonEditGraphicsView::removeSelectedItems()
if (m_nextStartNodeItem) { if (m_nextStartNodeItem) {
SkeletonEditNodeItem *nodeItem = m_nextStartNodeItem; SkeletonEditNodeItem *nodeItem = m_nextStartNodeItem;
setNextStartNodeItem(NULL); setNextStartNodeItem(NULL);
removeNodeItem(nodeItem->nextSidePair());
removeNodeItem(nodeItem); removeNodeItem(nodeItem);
emit nodesChanged(); emit nodesChanged();
} }
@ -401,13 +403,18 @@ void SkeletonEditGraphicsView::wheelEvent(QWheelEvent *event)
if (!m_backgroundLoaded) if (!m_backgroundLoaded)
return; return;
qreal delta = event->delta() / 10; qreal delta = event->delta() / 10;
if (fabs(delta) < 1) if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
delta = delta < 0 ? -1.0 : 1.0; if (delta > 0)
delta = 1;
else
delta = -1;
} else {
if (fabs(delta) < 1)
delta = delta < 0 ? -1.0 : 1.0;
}
AddItemRadius(m_pendingNodeItem, delta); AddItemRadius(m_pendingNodeItem, delta);
if (!m_inAddNodeMode && m_lastHoverNodeItem) { if (!m_inAddNodeMode && m_lastHoverNodeItem) {
//if (canAddItemRadius(m_lastHoverNodeItem, delta)) { AddItemRadius(m_lastHoverNodeItem, delta);
AddItemRadius(m_lastHoverNodeItem, delta);
//}
emit nodesChanged(); emit nodesChanged();
} }
} }

View File

@ -244,6 +244,8 @@ void SkeletonToMesh::process()
SkeletonSnapshot *skeleton = &groups[i]; SkeletonSnapshot *skeleton = &groups[i];
QRectF front = skeleton->boundingBoxFront(); QRectF front = skeleton->boundingBoxFront();
QRectF side = skeleton->boundingBoxSide(); QRectF side = skeleton->boundingBoxSide();
float canvasWidth = skeleton->canvas["width"].toFloat();
float canvasHeight = skeleton->canvas["height"].toFloat();
std::map<QString, int> bmeshNodeMap; std::map<QString, int> bmeshNodeMap;
@ -255,11 +257,11 @@ void SkeletonToMesh::process()
std::map<QString, std::map<QString, QString>>::iterator nextSidePair = skeleton->nodes.find(nodeIterator->second["nextSidePair"]); std::map<QString, std::map<QString, QString>>::iterator nextSidePair = skeleton->nodes.find(nodeIterator->second["nextSidePair"]);
if (nextSidePair == skeleton->nodes.end()) if (nextSidePair == skeleton->nodes.end())
continue; continue;
float x = (nodeIterator->second["x"].toFloat() - front.left() - front.height() / 2) / front.height(); float x = (nodeIterator->second["x"].toFloat() - front.left()) / canvasHeight;
float y = (nodeIterator->second["y"].toFloat() - front.top() - front.height() / 2) / front.height(); float y = (nodeIterator->second["y"].toFloat()) / canvasHeight;
float z = (nextSidePair->second["x"].toFloat() - side.left() - side.width() / 2) / side.height(); float z = (nextSidePair->second["x"].toFloat() - side.left()) / canvasHeight;
float r = nodeIterator->second["radius"].toFloat() / front.height(); float r = nodeIterator->second["radius"].toFloat() / canvasHeight;
float t = nextSidePair->second["radius"].toFloat() / side.height(); float t = nextSidePair->second["radius"].toFloat() / canvasHeight;
int bmeshNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, r, t); int bmeshNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, r, t);
printf("meshlite_bmesh_add_node x:%f y:%f z:%f r:%f t:%f nodeName:%s bmeshNodeId:%d\n", x, y, z, r, t, nodeIterator->first.toUtf8().constData(), bmeshNodeId); printf("meshlite_bmesh_add_node x:%f y:%f z:%f r:%f t:%f nodeName:%s bmeshNodeId:%d\n", x, y, z, r, t, nodeIterator->first.toUtf8().constData(), bmeshNodeId);
bmeshNodeMap[nodeIterator->first] = bmeshNodeId; bmeshNodeMap[nodeIterator->first] = bmeshNodeId;