Add toggleable options for generating
parent
01e8abf0cc
commit
d86004b46a
|
@ -26,7 +26,10 @@ SkeletonEditGraphicsView::SkeletonEditGraphicsView(QWidget *parent) :
|
|||
m_isMovingNodeItem(false),
|
||||
m_backgroundLoaded(false),
|
||||
m_modelWidget(NULL),
|
||||
m_modelWidgetProxy(NULL)
|
||||
m_modelWidgetProxy(NULL),
|
||||
m_combineEnabled(false),
|
||||
m_unionEnabled(true),
|
||||
m_subdivEnabled(false)
|
||||
{
|
||||
setScene(new QGraphicsScene());
|
||||
|
||||
|
@ -218,6 +221,15 @@ bool SkeletonEditGraphicsView::keyPress(QKeyEvent *event, const QPointF &scenePo
|
|||
if (event->key() == Qt::Key_A) {
|
||||
toggleAddNodeMode();
|
||||
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) {
|
||||
removeSelectedItems();
|
||||
processed = true;
|
||||
|
@ -448,6 +460,8 @@ bool SkeletonEditGraphicsView::wheel(QWheelEvent *event, const QPointF &scenePos
|
|||
processed = true;
|
||||
emit nodesChanged();
|
||||
}
|
||||
if (m_inAddNodeMode)
|
||||
processed = true;
|
||||
return processed;
|
||||
}
|
||||
|
||||
|
@ -562,6 +576,9 @@ void SkeletonEditGraphicsView::saveToSnapshot(SkeletonSnapshot *snapshot)
|
|||
{
|
||||
snapshot->canvas["width"] = QString("%1").arg(scene()->sceneRect().width());
|
||||
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 *> list = scene()->items();
|
||||
|
@ -675,4 +692,18 @@ void SkeletonEditGraphicsView::keyPressEvent(QKeyEvent *event)
|
|||
keyPress(event, QPointF());
|
||||
}
|
||||
|
||||
bool SkeletonEditGraphicsView::combineEnabled()
|
||||
{
|
||||
return m_combineEnabled;
|
||||
}
|
||||
|
||||
bool SkeletonEditGraphicsView::unionEnabled()
|
||||
{
|
||||
return m_unionEnabled;
|
||||
}
|
||||
|
||||
bool SkeletonEditGraphicsView::subdivEnabled()
|
||||
{
|
||||
return m_subdivEnabled;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ public:
|
|||
void saveToSnapshot(SkeletonSnapshot *snapshot);
|
||||
void loadFromSnapshot(SkeletonSnapshot *snapshot);
|
||||
ModelWidget *modelWidget();
|
||||
bool combineEnabled();
|
||||
bool unionEnabled();
|
||||
bool subdivEnabled();
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
|
@ -63,6 +66,9 @@ private:
|
|||
bool m_backgroundLoaded;
|
||||
ModelWidget *m_modelWidget;
|
||||
QGraphicsProxyWidget *m_modelWidgetProxy;
|
||||
bool m_combineEnabled;
|
||||
bool m_unionEnabled;
|
||||
bool m_subdivEnabled;
|
||||
private:
|
||||
void toggleAddNodeMode();
|
||||
void applyAddNodeMode();
|
||||
|
|
|
@ -54,6 +54,9 @@ void SkeletonToMesh::process()
|
|||
float frontMiddleX = m_snapshot.nodes[rootNodeId]["x"].toFloat();
|
||||
float frontMiddleY = m_snapshot.nodes[rootNodeId]["y"].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);
|
||||
|
||||
std::vector<int> meshIds;
|
||||
|
@ -64,6 +67,7 @@ void SkeletonToMesh::process()
|
|||
//QRectF side = skeleton->boundingBoxSide();
|
||||
//float canvasWidth = skeleton->canvas["width"].toFloat();
|
||||
//float canvasHeight = skeleton->canvas["height"].toFloat();
|
||||
float canvasHeight = globalFront.height();
|
||||
|
||||
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"]);
|
||||
if (nextSidePair == skeleton->nodes.end())
|
||||
continue;
|
||||
float x = (nodeIterator->second["x"].toFloat() - frontMiddleX) / globalFront.height();
|
||||
float y = (nodeIterator->second["y"].toFloat() - frontMiddleY) / globalFront.height();
|
||||
float z = (nextSidePair->second["x"].toFloat() - sideMiddleX) / globalFront.height();
|
||||
float r = nodeIterator->second["radius"].toFloat() / globalFront.height();
|
||||
float t = nextSidePair->second["radius"].toFloat() / globalFront.height();
|
||||
float x = (nodeIterator->second["x"].toFloat() - frontMiddleX) / canvasHeight;
|
||||
float y = (nodeIterator->second["y"].toFloat() - frontMiddleY) / canvasHeight;
|
||||
float z = (nextSidePair->second["x"].toFloat() - sideMiddleX) / canvasHeight;
|
||||
float r = nodeIterator->second["radius"].toFloat() / canvasHeight;
|
||||
float t = nextSidePair->second["radius"].toFloat() / canvasHeight;
|
||||
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);
|
||||
bmeshNodeMap[nodeIterator->first] = bmeshNodeId;
|
||||
|
@ -106,8 +110,21 @@ void SkeletonToMesh::process()
|
|||
}
|
||||
|
||||
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) {
|
||||
mergedMeshId = meshlite_subdivide(meshliteContext, mergedMeshId);
|
||||
}
|
||||
}
|
||||
if (mergedMeshId > 0) {
|
||||
if (combineEnabled) {
|
||||
mergedMeshId = meshlite_combine_adj_faces(meshliteContext, mergedMeshId);
|
||||
}
|
||||
m_mesh = new Mesh(meshliteContext, mergedMeshId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
QColor Theme::red = QColor(0xff, 0xff, 0xff);
|
||||
QColor Theme::green = QColor(0xff, 0xff, 0xff);
|
||||
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::checkedAlpha = 1.0;
|
||||
float Theme::edgeAlpha = Theme::normalAlpha / 2;
|
||||
float Theme::edgeAlpha = 1.0;
|
||||
float Theme::fillAlpha = 50.0 / 255;
|
||||
int Theme::skeletonNodeBorderSize = 2;
|
||||
int Theme::skeletonEdgeWidth = 2;
|
||||
|
|
|
@ -115,7 +115,13 @@ int makeMeshliteMeshFromCgal(void *meshlite, CgalMesh *mesh)
|
|||
CgalMesh *unionCgalMeshs(CgalMesh *first, CgalMesh *second)
|
||||
{
|
||||
CgalMesh *mesh = new CgalMesh;
|
||||
if (!PMP::corefine_and_compute_union(*first, *second, *mesh)) {
|
||||
try {
|
||||
if (!PMP::corefine_and_compute_union(*first, *second, *mesh)) {
|
||||
delete mesh;
|
||||
return NULL;
|
||||
}
|
||||
} catch (...) {
|
||||
delete mesh;
|
||||
return NULL;
|
||||
}
|
||||
return mesh;
|
||||
|
@ -236,9 +242,13 @@ int unionMeshs(void *meshliteContext, const std::vector<int> &meshIds)
|
|||
} catch (...) {
|
||||
// ignore;
|
||||
}
|
||||
delete mergedExternalMesh;
|
||||
delete externalMeshs[i];
|
||||
mergedExternalMesh = unionedExternalMesh;
|
||||
if (unionedExternalMesh) {
|
||||
delete mergedExternalMesh;
|
||||
mergedExternalMesh = unionedExternalMesh;
|
||||
} else {
|
||||
// TOOD:
|
||||
}
|
||||
}
|
||||
if (mergedExternalMesh) {
|
||||
int mergedMeshId = makeMeshliteMeshFromExternal(meshliteContext, mergedExternalMesh);
|
||||
|
@ -247,11 +257,16 @@ int unionMeshs(void *meshliteContext, const std::vector<int> &meshIds)
|
|||
}
|
||||
}
|
||||
#else
|
||||
return mergeMeshs(meshliteContext, meshIds);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mergeMeshs(void *meshliteContext, const std::vector<int> &meshIds)
|
||||
{
|
||||
int mergedMeshId = meshIds[0];
|
||||
for (size_t i = 1; i < meshIds.size(); i++) {
|
||||
mergedMeshId = meshlite_merge(meshliteContext, mergedMeshId, meshIds[i]);
|
||||
}
|
||||
return mergedMeshId;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define UNION_MESH_H
|
||||
#include <vector>
|
||||
|
||||
int mergeMeshs(void *meshliteContext, const std::vector<int> &meshIds);
|
||||
int unionMeshs(void *meshliteContext, const std::vector<int> &meshIds);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue