Skip to content

Commit

Permalink
Add thickness parameter for part.
Browse files Browse the repository at this point in the history
It's showed as mini button on part list widget, this parameter can be use to make fish body like mesh.
  • Loading branch information
huxingyi committed Apr 17, 2018
1 parent 87e64fc commit ce41e65
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 26 deletions.
3 changes: 3 additions & 0 deletions dust3d.pro
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ HEADERS += src/logbrowser.h
SOURCES += src/logbrowserdialog.cpp
HEADERS += src/logbrowserdialog.h

SOURCES += src/floatnumberwidget.cpp
HEADERS += src/floatnumberwidget.h

SOURCES += src/main.cpp

HEADERS += src/version.h
Expand Down
50 changes: 50 additions & 0 deletions src/floatnumberwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <QtWidgets>
#include "floatnumberwidget.h"

FloatNumberWidget::FloatNumberWidget(QWidget *parent) :
QWidget(parent)
{
m_slider = new QSlider(Qt::Horizontal, this);
m_slider->setRange(0, 100);

m_label = new QLabel(this);
m_label->setAlignment(Qt::AlignCenter);
m_label->setNum(0);
m_label->setFixedWidth(30);

connect(m_slider, &QAbstractSlider::valueChanged, [=](int value) {
float fvalue = value / 100.0;
m_label->setText(QString().sprintf("%.2f", fvalue));
emit valueChanged(fvalue);
});

QBoxLayout *popupLayout = new QHBoxLayout(this);
popupLayout->setMargin(2);
popupLayout->addWidget(m_slider);
popupLayout->addWidget(m_label);
}

void FloatNumberWidget::setRange(float min, float max)
{
m_slider->setRange(min * 100, max * 100);
}

void FloatNumberWidget::increaseValue()
{
m_slider->triggerAction(QSlider::SliderPageStepAdd);
}

void FloatNumberWidget::descreaseValue()
{
m_slider->triggerAction(QSlider::SliderPageStepSub);
}

float FloatNumberWidget::value() const
{
return m_slider->value() / 100.0;
}

void FloatNumberWidget::setValue(float value)
{
m_slider->setValue(value * 100);
}
29 changes: 29 additions & 0 deletions src/floatnumberwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef FLOAT_NUMBER_WIDGET_H
#define FLOAT_NUMBER_WIDGET_H
#include <QToolButton>

QT_FORWARD_DECLARE_CLASS(QLabel)
QT_FORWARD_DECLARE_CLASS(QSlider)

class FloatNumberWidget : public QWidget
{
Q_OBJECT
public:
explicit FloatNumberWidget(QWidget *parent = nullptr);
void setRange(float min, float max);
float value() const;

public slots:
void increaseValue();
void descreaseValue();
void setValue(float value);

signals:
void valueChanged(float value);

private:
QLabel *m_label = nullptr;
QSlider *m_slider = nullptr;
};

#endif
3 changes: 3 additions & 0 deletions src/meshgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ void MeshGenerator::process()
int bmeshId = meshlite_bmesh_create(meshliteContext);
if (subdived)
meshlite_bmesh_set_cut_subdiv_count(meshliteContext, bmeshId, 1);
QString thicknessString = valueOfKeyInMapOrEmpty(part->second, "thickness");
if (!thicknessString.isEmpty())
meshlite_bmesh_set_thickness(meshliteContext, bmeshId, thicknessString.toFloat());
if (MeshGenerator::enableDebug)
meshlite_bmesh_enable_debug(meshliteContext, bmeshId, 1);
partBmeshMap[partIdIt] = bmeshId;
Expand Down
17 changes: 17 additions & 0 deletions src/skeletondocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ void SkeletonDocument::toSnapshot(SkeletonSnapshot *snapshot, const std::set<QUu
part["disabled"] = partIt.second.disabled ? "true" : "false";
part["xMirrored"] = partIt.second.xMirrored ? "true" : "false";
part["zMirrored"] = partIt.second.zMirrored ? "true" : "false";
if (partIt.second.thicknessAdjusted())
part["thickness"] = QString::number(partIt.second.thickness);
if (!partIt.second.name.isEmpty())
part["name"] = partIt.second.name;
snapshot->parts[part["id"]] = part;
Expand Down Expand Up @@ -655,6 +657,9 @@ void SkeletonDocument::addFromSnapshot(const SkeletonSnapshot &snapshot)
part.disabled = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "disabled"));
part.xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "xMirrored"));
part.zMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "zMirrored"));
const auto &thicknessIt = partKv.second.find("thickness");
if (thicknessIt != partKv.second.end())
part.setThickness(thicknessIt->second.toFloat());
partMap[part.id] = part;
}
for (const auto &nodeKv : snapshot.nodes) {
Expand Down Expand Up @@ -924,6 +929,18 @@ void SkeletonDocument::setPartZmirrorState(QUuid partId, bool mirrored)
emit skeletonChanged();
}

void SkeletonDocument::setPartThickness(QUuid partId, float thickness)
{
auto part = partMap.find(partId);
if (part == partMap.end()) {
qDebug() << "Part not found:" << partId;
return;
}
part->second.setThickness(thickness);
emit partThicknessChanged(partId);
emit skeletonChanged();
}

void SkeletonDocument::saveSnapshot()
{
if (m_undoItems.size() + 1 > m_maxSnapshot)
Expand Down
20 changes: 19 additions & 1 deletion src/skeletondocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <set>
#include <deque>
#include <QImage>
#include <cmath>
#include "skeletonsnapshot.h"
#include "mesh.h"
#include "meshgenerator.h"
Expand Down Expand Up @@ -70,6 +71,7 @@ class SkeletonPart
bool disabled;
bool xMirrored;
bool zMirrored;
float thickness;
QImage preview;
std::vector<QUuid> nodeIds;
SkeletonPart(const QUuid &withId=QUuid()) :
Expand All @@ -78,10 +80,23 @@ class SkeletonPart
subdived(false),
disabled(false),
xMirrored(false),
zMirrored(false)
zMirrored(false),
thickness(1.0)
{
id = withId.isNull() ? QUuid::createUuid() : withId;
}
void setThickness(float toThickness)
{
if (toThickness < 0)
toThickness = 0;
else if (toThickness > 2)
toThickness = 2;
thickness = toThickness;
}
bool thicknessAdjusted() const
{
return fabs(thickness - 1.0) >= 0.01;
}
bool isEditVisible() const
{
return visible && !disabled;
Expand All @@ -94,6 +109,7 @@ class SkeletonPart
disabled = other.disabled;
xMirrored = other.xMirrored;
zMirrored = other.zMirrored;
thickness = other.thickness;
}
};

Expand Down Expand Up @@ -145,6 +161,7 @@ class SkeletonDocument : public QObject
void partDisableStateChanged(QUuid partId);
void partXmirrorStateChanged(QUuid partId);
void partZmirrorStateChanged(QUuid partId);
void partThicknessChanged(QUuid partId);
void cleanup();
void originChanged();
void xlockStateChanged();
Expand Down Expand Up @@ -203,6 +220,7 @@ public slots:
void setPartDisableState(QUuid partId, bool disabled);
void setPartXmirrorState(QUuid partId, bool mirrored);
void setPartZmirrorState(QUuid partId, bool mirrored);
void setPartThickness(QUuid partId, float thickness);
void saveSnapshot();
void undo();
void redo();
Expand Down
16 changes: 8 additions & 8 deletions src/skeletondocumentwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,37 +182,37 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
m_fileMenu = menuBar()->addMenu(tr("File"));

m_newWindowAction = new QAction(tr("New Window"), this);
connect(m_newWindowAction, &QAction::triggered, this, &SkeletonDocumentWindow::newWindow);
connect(m_newWindowAction, &QAction::triggered, this, &SkeletonDocumentWindow::newWindow, Qt::QueuedConnection);
m_fileMenu->addAction(m_newWindowAction);

m_newDocumentAction = new QAction(tr("New"), this);
connect(m_newDocumentAction, &QAction::triggered, this, &SkeletonDocumentWindow::newDocument);
m_fileMenu->addAction(m_newDocumentAction);

m_openAction = new QAction(tr("Open..."), this);
connect(m_openAction, &QAction::triggered, this, &SkeletonDocumentWindow::open);
connect(m_openAction, &QAction::triggered, this, &SkeletonDocumentWindow::open, Qt::QueuedConnection);
m_fileMenu->addAction(m_openAction);

m_saveAction = new QAction(tr("Save"), this);
connect(m_saveAction, &QAction::triggered, this, &SkeletonDocumentWindow::save);
connect(m_saveAction, &QAction::triggered, this, &SkeletonDocumentWindow::save, Qt::QueuedConnection);
m_fileMenu->addAction(m_saveAction);

m_saveAsAction = new QAction(tr("Save As..."), this);
connect(m_saveAsAction, &QAction::triggered, this, &SkeletonDocumentWindow::saveAs);
connect(m_saveAsAction, &QAction::triggered, this, &SkeletonDocumentWindow::saveAs, Qt::QueuedConnection);
m_fileMenu->addAction(m_saveAsAction);

m_saveAllAction = new QAction(tr("Save All"), this);
connect(m_saveAllAction, &QAction::triggered, this, &SkeletonDocumentWindow::saveAll);
connect(m_saveAllAction, &QAction::triggered, this, &SkeletonDocumentWindow::saveAll, Qt::QueuedConnection);
m_fileMenu->addAction(m_saveAllAction);

m_fileMenu->addSeparator();

m_exportAction = new QAction(tr("Export..."), this);
connect(m_exportAction, &QAction::triggered, this, &SkeletonDocumentWindow::exportResult);
connect(m_exportAction, &QAction::triggered, this, &SkeletonDocumentWindow::exportResult, Qt::QueuedConnection);
m_fileMenu->addAction(m_exportAction);

m_changeTurnaroundAction = new QAction(tr("Change Turnaround..."), this);
connect(m_changeTurnaroundAction, &QAction::triggered, this, &SkeletonDocumentWindow::changeTurnaround);
connect(m_changeTurnaroundAction, &QAction::triggered, this, &SkeletonDocumentWindow::changeTurnaround, Qt::QueuedConnection);
m_fileMenu->addAction(m_changeTurnaroundAction);

connect(m_fileMenu, &QMenu::aboutToShow, [=]() {
Expand Down Expand Up @@ -422,7 +422,7 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(m_document, &SkeletonDocument::partSubdivStateChanged, partListWidget, &SkeletonPartListWidget::partSubdivStateChanged);
connect(m_document, &SkeletonDocument::partDisableStateChanged, partListWidget, &SkeletonPartListWidget::partDisableStateChanged);
connect(m_document, &SkeletonDocument::partXmirrorStateChanged, partListWidget, &SkeletonPartListWidget::partXmirrorStateChanged);
connect(m_document, &SkeletonDocument::partZmirrorStateChanged, partListWidget, &SkeletonPartListWidget::partZmirrorStateChanged);
connect(m_document, &SkeletonDocument::partThicknessChanged, partListWidget, &SkeletonPartListWidget::partThicknessChanged);
connect(m_document, &SkeletonDocument::cleanup, partListWidget, &SkeletonPartListWidget::partListChanged);

connect(m_document, &SkeletonDocument::skeletonChanged, m_document, &SkeletonDocument::generateMesh);
Expand Down

0 comments on commit ce41e65

Please sign in to comment.