Add toggleable options for generating

master
Jeremy Hu 2018-03-30 22:05:47 +08:00
parent 01e8abf0cc
commit d86004b46a
6 changed files with 85 additions and 15 deletions

View File

@ -26,7 +26,10 @@ SkeletonEditGraphicsView::SkeletonEditGraphicsView(QWidget *parent) :
m_isMovingNodeItem(false), m_isMovingNodeItem(false),
m_backgroundLoaded(false), m_backgroundLoaded(false),
m_modelWidget(NULL), m_modelWidget(NULL),
m_modelWidgetProxy(NULL) m_modelWidgetProxy(NULL),
m_combineEnabled(false),
m_unionEnabled(true),
m_subdivEnabled(false)
{ {
setScene(new QGraphicsScene()); setScene(new QGraphicsScene());
@ -218,6 +221,15 @@ bool SkeletonEditGraphicsView::keyPress(QKeyEvent *event, const QPointF &scenePo
if (event->key() == Qt::Key_A) { if (event->key() == Qt::Key_A) {
toggleAddNodeMode(); toggleAddNodeMode();
processed = true; processed = true;
} else if (event->key() == Qt::Key_C) {
m_combineEnabled = !m_combineEnabled;
emit nodesChanged();
} else if (event->key() == Qt::Key_U) {
m_unionEnabled = !m_unionEnabled;
emit nodesChanged();
} else if (event->key() == Qt::Key_S) {
m_subdivEnabled = !m_subdivEnabled;
emit nodesChanged();
} else if (event->key() == Qt::Key_Delete || event->key() ==Qt::Key_Backspace) { } else if (event->key() == Qt::Key_Delete || event->key() ==Qt::Key_Backspace) {
removeSelectedItems(); removeSelectedItems();
processed = true; processed = true;
@ -448,6 +460,8 @@ bool SkeletonEditGraphicsView::wheel(QWheelEvent *event, const QPointF &scenePos
processed = true; processed = true;
emit nodesChanged(); emit nodesChanged();
} }
if (m_inAddNodeMode)
processed = true;
return processed; return processed;
} }
@ -562,6 +576,9 @@ void SkeletonEditGraphicsView::saveToSnapshot(SkeletonSnapshot *snapshot)
{ {
snapshot->canvas["width"] = QString("%1").arg(scene()->sceneRect().width()); snapshot->canvas["width"] = QString("%1").arg(scene()->sceneRect().width());
snapshot->canvas["height"] = QString("%1").arg(scene()->sceneRect().height()); snapshot->canvas["height"] = QString("%1").arg(scene()->sceneRect().height());
snapshot->canvas["combine"] = m_combineEnabled ? "true" : "false";
snapshot->canvas["union"] = m_unionEnabled ? "true" : "false";
snapshot->canvas["subdiv"] = m_subdivEnabled ? "true" : "false";
QList<QGraphicsItem *>::iterator it; QList<QGraphicsItem *>::iterator it;
QList<QGraphicsItem *> list = scene()->items(); QList<QGraphicsItem *> list = scene()->items();
@ -675,4 +692,18 @@ void SkeletonEditGraphicsView::keyPressEvent(QKeyEvent *event)
keyPress(event, QPointF()); keyPress(event, QPointF());
} }
bool SkeletonEditGraphicsView::combineEnabled()
{
return m_combineEnabled;
}
bool SkeletonEditGraphicsView::unionEnabled()
{
return m_unionEnabled;
}
bool SkeletonEditGraphicsView::subdivEnabled()
{
return m_subdivEnabled;
}

View File

@ -41,6 +41,9 @@ public:
void saveToSnapshot(SkeletonSnapshot *snapshot); void saveToSnapshot(SkeletonSnapshot *snapshot);
void loadFromSnapshot(SkeletonSnapshot *snapshot); void loadFromSnapshot(SkeletonSnapshot *snapshot);
ModelWidget *modelWidget(); ModelWidget *modelWidget();
bool combineEnabled();
bool unionEnabled();
bool subdivEnabled();
protected: protected:
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
@ -63,6 +66,9 @@ private:
bool m_backgroundLoaded; bool m_backgroundLoaded;
ModelWidget *m_modelWidget; ModelWidget *m_modelWidget;
QGraphicsProxyWidget *m_modelWidgetProxy; QGraphicsProxyWidget *m_modelWidgetProxy;
bool m_combineEnabled;
bool m_unionEnabled;
bool m_subdivEnabled;
private: private:
void toggleAddNodeMode(); void toggleAddNodeMode();
void applyAddNodeMode(); void applyAddNodeMode();

View File

@ -54,6 +54,9 @@ void SkeletonToMesh::process()
float frontMiddleX = m_snapshot.nodes[rootNodeId]["x"].toFloat(); float frontMiddleX = m_snapshot.nodes[rootNodeId]["x"].toFloat();
float frontMiddleY = m_snapshot.nodes[rootNodeId]["y"].toFloat(); float frontMiddleY = m_snapshot.nodes[rootNodeId]["y"].toFloat();
float sideMiddleX = m_snapshot.nodes[m_snapshot.nodes[rootNodeId]["nextSidePair"]]["x"].toFloat(); float sideMiddleX = m_snapshot.nodes[m_snapshot.nodes[rootNodeId]["nextSidePair"]]["x"].toFloat();
bool combineEnabled = "true" == m_snapshot.canvas["combine"];
bool unionEnabled = "true" == m_snapshot.canvas["union"];
bool subdivEnabled = "true" == m_snapshot.canvas["subdiv"];
m_snapshot.splitByConnectivity(&groups); m_snapshot.splitByConnectivity(&groups);
std::vector<int> meshIds; std::vector<int> meshIds;
@ -64,6 +67,7 @@ void SkeletonToMesh::process()
//QRectF side = skeleton->boundingBoxSide(); //QRectF side = skeleton->boundingBoxSide();
//float canvasWidth = skeleton->canvas["width"].toFloat(); //float canvasWidth = skeleton->canvas["width"].toFloat();
//float canvasHeight = skeleton->canvas["height"].toFloat(); //float canvasHeight = skeleton->canvas["height"].toFloat();
float canvasHeight = globalFront.height();
std::map<QString, int> bmeshNodeMap; std::map<QString, int> bmeshNodeMap;
@ -75,11 +79,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() - frontMiddleX) / globalFront.height(); float x = (nodeIterator->second["x"].toFloat() - frontMiddleX) / canvasHeight;
float y = (nodeIterator->second["y"].toFloat() - frontMiddleY) / globalFront.height(); float y = (nodeIterator->second["y"].toFloat() - frontMiddleY) / canvasHeight;
float z = (nextSidePair->second["x"].toFloat() - sideMiddleX) / globalFront.height(); float z = (nextSidePair->second["x"].toFloat() - sideMiddleX) / canvasHeight;
float r = nodeIterator->second["radius"].toFloat() / globalFront.height(); float r = nodeIterator->second["radius"].toFloat() / canvasHeight;
float t = nextSidePair->second["radius"].toFloat() / globalFront.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;
@ -106,8 +110,21 @@ void SkeletonToMesh::process()
} }
if (meshIds.size() > 0) { if (meshIds.size() > 0) {
int mergedMeshId = unionMeshs(meshliteContext, meshIds); int mergedMeshId = 0;
if (unionEnabled) {
mergedMeshId = unionMeshs(meshliteContext, meshIds);
} else {
mergedMeshId = mergeMeshs(meshliteContext, meshIds);
}
if (subdivEnabled) {
if (mergedMeshId > 0) { if (mergedMeshId > 0) {
mergedMeshId = meshlite_subdivide(meshliteContext, mergedMeshId);
}
}
if (mergedMeshId > 0) {
if (combineEnabled) {
mergedMeshId = meshlite_combine_adj_faces(meshliteContext, mergedMeshId);
}
m_mesh = new Mesh(meshliteContext, mergedMeshId); m_mesh = new Mesh(meshliteContext, mergedMeshId);
} }
} }

View File

@ -17,10 +17,10 @@
QColor Theme::red = QColor(0xff, 0xff, 0xff); QColor Theme::red = QColor(0xff, 0xff, 0xff);
QColor Theme::green = QColor(0xff, 0xff, 0xff); QColor Theme::green = QColor(0xff, 0xff, 0xff);
QColor Theme::blue = QColor(0x2a, 0x5a, 0xac); QColor Theme::blue = QColor(0x2a, 0x5a, 0xac);
float Theme::normalAlpha = 128.0 / 255; float Theme::normalAlpha = 96.0 / 255;
float Theme::branchAlpha = 64.0 / 255; float Theme::branchAlpha = 64.0 / 255;
float Theme::checkedAlpha = 1.0; float Theme::checkedAlpha = 1.0;
float Theme::edgeAlpha = Theme::normalAlpha / 2; float Theme::edgeAlpha = 1.0;
float Theme::fillAlpha = 50.0 / 255; float Theme::fillAlpha = 50.0 / 255;
int Theme::skeletonNodeBorderSize = 2; int Theme::skeletonNodeBorderSize = 2;
int Theme::skeletonEdgeWidth = 2; int Theme::skeletonEdgeWidth = 2;

View File

@ -115,7 +115,13 @@ int makeMeshliteMeshFromCgal(void *meshlite, CgalMesh *mesh)
CgalMesh *unionCgalMeshs(CgalMesh *first, CgalMesh *second) CgalMesh *unionCgalMeshs(CgalMesh *first, CgalMesh *second)
{ {
CgalMesh *mesh = new CgalMesh; CgalMesh *mesh = new CgalMesh;
try {
if (!PMP::corefine_and_compute_union(*first, *second, *mesh)) { if (!PMP::corefine_and_compute_union(*first, *second, *mesh)) {
delete mesh;
return NULL;
}
} catch (...) {
delete mesh;
return NULL; return NULL;
} }
return mesh; return mesh;
@ -236,9 +242,13 @@ int unionMeshs(void *meshliteContext, const std::vector<int> &meshIds)
} catch (...) { } catch (...) {
// ignore; // ignore;
} }
delete mergedExternalMesh;
delete externalMeshs[i]; delete externalMeshs[i];
if (unionedExternalMesh) {
delete mergedExternalMesh;
mergedExternalMesh = unionedExternalMesh; mergedExternalMesh = unionedExternalMesh;
} else {
// TOOD:
}
} }
if (mergedExternalMesh) { if (mergedExternalMesh) {
int mergedMeshId = makeMeshliteMeshFromExternal(meshliteContext, mergedExternalMesh); int mergedMeshId = makeMeshliteMeshFromExternal(meshliteContext, mergedExternalMesh);
@ -247,11 +257,16 @@ int unionMeshs(void *meshliteContext, const std::vector<int> &meshIds)
} }
} }
#else #else
return mergeMeshs(meshliteContext, meshIds);
#endif
return 0;
}
int mergeMeshs(void *meshliteContext, const std::vector<int> &meshIds)
{
int mergedMeshId = meshIds[0]; int mergedMeshId = meshIds[0];
for (size_t i = 1; i < meshIds.size(); i++) { for (size_t i = 1; i < meshIds.size(); i++) {
mergedMeshId = meshlite_merge(meshliteContext, mergedMeshId, meshIds[i]); mergedMeshId = meshlite_merge(meshliteContext, mergedMeshId, meshIds[i]);
} }
return mergedMeshId; return mergedMeshId;
#endif
return 0;
} }

View File

@ -2,6 +2,7 @@
#define UNION_MESH_H #define UNION_MESH_H
#include <vector> #include <vector>
int mergeMeshs(void *meshliteContext, const std::vector<int> &meshIds);
int unionMeshs(void *meshliteContext, const std::vector<int> &meshIds); int unionMeshs(void *meshliteContext, const std::vector<int> &meshIds);
#endif #endif