From 4dda7e656b0060c3b8bd4e31e19f578e41d78f9f Mon Sep 17 00:00:00 2001 From: kazu Date: Tue, 16 Jan 2018 12:43:45 +0100 Subject: [PATCH] added nav-mesh support to indoor-map some fixes/changes --- IndoorMap.pro | 12 +- MainController.cpp | 20 ++- MainController.h | 5 +- MainWindow.cpp | 14 +- MainWindow.h | 5 +- MainWindow.ui | 39 ++++-- mapview/2D/MV2DElementStair.h | 4 +- mapview/3D/MV3DElementStair.h | 3 +- mapview/3D/MapView3D.cpp | 79 ++++++++---- mapview/3D/MapView3D.h | 28 +++- mapview/3DNavMesh/NavMeshModel.h | 85 ++++++++++++ mapview/3DNavMesh/NavMeshRenderer.h | 172 +++++++++++++++++++++++++ mapview/3DNavMesh/QNavMeshSettings.cpp | 87 +++++++++++++ mapview/3DNavMesh/QNavMeshSettings.h | 24 ++++ mapview/model/MMFloor.h | 5 + mapview/model/MapLayer.h | 2 +- 16 files changed, 524 insertions(+), 60 deletions(-) create mode 100644 mapview/3DNavMesh/NavMeshModel.h create mode 100644 mapview/3DNavMesh/NavMeshRenderer.h create mode 100644 mapview/3DNavMesh/QNavMeshSettings.cpp create mode 100644 mapview/3DNavMesh/QNavMeshSettings.h diff --git a/IndoorMap.pro b/IndoorMap.pro index fe373c8..7103d93 100644 --- a/IndoorMap.pro +++ b/IndoorMap.pro @@ -42,7 +42,8 @@ SOURCES += \ params/MetaEditWidget.cpp \ params/MetaEditModel.cpp \ mapview/2D/MapView2D.cpp \ - misc/LINTView.cpp + misc/LINTView.cpp \ + mapview/3DNavMesh/QNavMeshSettings.cpp HEADERS += MainWindow.h \ @@ -165,13 +166,18 @@ HEADERS += MainWindow.h \ mapview/2D/tools/ToolNewBeacon.h \ mapview/2D/tools/ToolNewGroundTruth.h \ mapview/2D/tools/ToolNewPOI.h \ - mapview/3D/MV3DElementElevator.h + mapview/3D/MV3DElementElevator.h \ + mapview/3DNavMesh/NavMeshView.h \ + mapview/3DNavMesh/NavMeshRenderer.h \ + mapview/3DNavMesh/NavMeshModel.h \ + mapview/3DNavMesh/QNavMeshSettings.h FORMS += MainWindow.ui SOURCES += \ - ../Indoor/lib/tinyxml/tinyxml2.cpp + ../Indoor/lib/tinyxml/tinyxml2.cpp \ + ../Indoor/lib/Recast/*.cpp RESOURCES += \ res.qrc diff --git a/MainController.cpp b/MainController.cpp index 94662af..7843b7d 100644 --- a/MainController.cpp +++ b/MainController.cpp @@ -87,8 +87,9 @@ MainController::MainController() { connect(mw->getActionWidget(), SIGNAL(onSave()), this, SLOT(onSave())); // 3D view change - connect(mw, SIGNAL(onShow3DFloorplan()), this, SLOT(onShow3DFloorplan())); - connect(mw, SIGNAL(onShow3DGrid()), this, SLOT(onShow3DGrid())); + connect(mw, SIGNAL(onShow3DFloorplan(bool)), this, SLOT(onSetShow3DFloorplan(bool))); + connect(mw, SIGNAL(onShow3DGrid(bool)), this, SLOT(onSetShow3DGrid(bool))); + connect(mw, SIGNAL(onShow3DNavMesh(bool)), this, SLOT(onSetShow3DNavMesh(bool))); // 3D grid view config connect(mw, &MainWindow::onGridNodeColorImp, [&] () {mw->getMapView3D()->getGridRenderer()->setNodeColorMode(GridRendererColorMode::SHOW_NODE_IMPORTANCE);} ); @@ -99,8 +100,9 @@ MainController::MainController() { //mapModel->load("../IndoorMap/maps/SHL38_no_elev.xml"); //mapModel->load("/apps/testmap.xml"); //mapModel->load("/apps/map24b.xml"); + //mapModel->load("/apps/SHL41.xml"); - mapModel->load("/apps/SHL41.xml"); + mapModel->load("/mnt/vm/paper/diss/data/maps/SHL41_nm.xml"); //mapModel->load("/apps/paper/diss/data/maps/map_elevator2.xml"); //mapModel->load("/apps/paper/diss/data/maps/map_issue6.xml"); @@ -145,12 +147,16 @@ void MainController::onLayerVisibilityChanged(MapLayer *layer, const bool visibl (void) visible; } -void MainController::onShow3DFloorplan() { - mw->getMapView3D()->showFloorplan(); +void MainController::onSetShow3DFloorplan(bool show) { + mw->getMapView3D()->setShowFloorplan(show); } -void MainController::onShow3DGrid() { - mw->getMapView3D()->showGrid(); +void MainController::onSetShow3DGrid(bool show) { + mw->getMapView3D()->setShowGrid(show); +} + +void MainController::onSetShow3DNavMesh(bool show) { + mw->getMapView3D()->setShowNavMesh(show); } void MainController::layerSelected(QModelIndex idx) { diff --git a/MainController.h b/MainController.h index 67520e5..6a1acd2 100644 --- a/MainController.h +++ b/MainController.h @@ -65,8 +65,9 @@ public slots: private slots: - void onShow3DFloorplan(); - void onShow3DGrid(); + void onSetShow3DFloorplan(bool show); + void onSetShow3DGrid(bool show); + void onSetShow3DNavMesh(bool show); private: diff --git a/MainWindow.cpp b/MainWindow.cpp index bd39270..224f3c4 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -114,14 +114,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // ui->layTree->addWidget(actionWidget); - // show mode - QActionGroup* grpMode = new QActionGroup(this); - grpMode->addAction(ui->actShow3DFloorplan); - grpMode->addAction(ui->actShow3DGrid); +// // show mode (radio buttons) +// QActionGroup* grpMode = new QActionGroup(this); +// grpMode->addAction(ui->actShow3DFloorplan); +// grpMode->addAction(ui->actShow3DGrid); +// grpMode->addAction(ui->actShow3DNavMesh); connect(ui->actShow2D, SIGNAL(triggered(bool)), this, SIGNAL(onShow2D())); - connect(ui->actShow3DGrid, SIGNAL(triggered(bool)), this, SIGNAL(onShow3DGrid())); - connect(ui->actShow3DFloorplan, SIGNAL(triggered(bool)), this, SIGNAL(onShow3DFloorplan())); + connect(ui->actShow3DGrid, SIGNAL(triggered(bool)), this, SIGNAL(onShow3DGrid(bool))); + connect(ui->actShow3DFloorplan, SIGNAL(triggered(bool)), this, SIGNAL(onShow3DFloorplan(bool))); + connect(ui->actShow3DNavMesh, SIGNAL(triggered(bool)), this, SIGNAL(onShow3DNavMesh(bool))); // node coloring diff --git a/MainWindow.h b/MainWindow.h index f69e8c5..2314a1f 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -40,8 +40,9 @@ public: signals: void onShow2D(); - void onShow3DFloorplan(); - void onShow3DGrid(); + void onShow3DFloorplan(bool show); + void onShow3DGrid(bool show); + void onShow3DNavMesh(bool show); void onGridShowEdges(bool); void onGridNodeColorImp(); void onGridNodeColorType(); diff --git a/MainWindow.ui b/MainWindow.ui index 88da9ec..c0a76bd 100644 --- a/MainWindow.ui +++ b/MainWindow.ui @@ -23,30 +23,31 @@ 0 0 777 - 26 + 30 - View + &View - 3D + &3D + - Grid + &Grid - node color + &node color @@ -62,15 +63,18 @@ true - 2D + &2D true + + true + - Floorplan + &Floorplan @@ -78,7 +82,7 @@ true - show edges + &show edges @@ -86,7 +90,7 @@ true - node type + &node type @@ -94,7 +98,7 @@ true - node importance + node &importance @@ -102,7 +106,20 @@ true - Grid + &Grid + + + + + NavMesh + + + + + true + + + &NavMesh diff --git a/mapview/2D/MV2DElementStair.h b/mapview/2D/MV2DElementStair.h index 566c4cf..816d152 100644 --- a/mapview/2D/MV2DElementStair.h +++ b/mapview/2D/MV2DElementStair.h @@ -104,8 +104,8 @@ public: QLinearGradient gradient(p.s.xms(part.start.x), p.s.yms(part.start.y), p.s.xms(part.end.x), p.s.yms(part.end.y)); const float p1 = 0.1 + clamp01( part.start.z / floor->height) * 0.8; const float p2 = 0.1 + clamp01( part.end.z / floor->height) * 0.8; - gradient.setColorAt(0, QColor(p1*255, p1*255, p1*255, 128)); - gradient.setColorAt(1, QColor(p2*255, p2*255, p2*255, 128)); + gradient.setColorAt(0, QColor(p1*128, p1*128, p1*255, 128)); + gradient.setColorAt(1, QColor(p2*128, p2*128, p2*255, 128)); p.setBrush(gradient); p.setPen(QColor(0,0,0,128)); diff --git a/mapview/3D/MV3DElementStair.h b/mapview/3D/MV3DElementStair.h index 2d27dd4..d6b327c 100644 --- a/mapview/3D/MV3DElementStair.h +++ b/mapview/3D/MV3DElementStair.h @@ -26,7 +26,8 @@ protected: glDisable(GL_CULL_FACE); - glColor3f(1.0, 0.55, 0.55); + //glColor3f(1.0, 0.55, 0.55); + glColor3f(0.3, 0.3, 0.3); glBegin(GL_QUADS); const std::vector parts = stair->getParts(); diff --git a/mapview/3D/MapView3D.cpp b/mapview/3D/MapView3D.cpp index 883b0cf..171f9f2 100644 --- a/mapview/3D/MapView3D.cpp +++ b/mapview/3D/MapView3D.cpp @@ -7,6 +7,9 @@ #include "../3DGrid/GridModel.h" #include "../3DGrid/GridRenderer.h" +#include "../3DNavMesh/NavMeshModel.h" +#include "../3DNavMesh/NavMeshRenderer.h" + MapView3D::MapView3D(QWidget *parent) : QGLWidget(parent) { rot.x = 45; @@ -180,12 +183,20 @@ void MapView3D::wheelEvent(QWheelEvent* e) { } -void MapView3D::showFloorplan() { - if (gridModel) {delete gridModel; gridModel = nullptr;} +void MapView3D::setShowFloorplan(bool show) { + + this->showFloorplan = show; + + //if (gridModel) {delete gridModel; gridModel = nullptr;} + //if (navMeshModel) {delete navMeshModel; navMeshModel = nullptr;} update(); + } -void MapView3D::showGrid() { +void MapView3D::setShowGrid(bool show) { + + this->showGrid = show; + if (!show) {update(); return;} // delete the previous grid (if any) if (gridModel) {delete gridModel; gridModel = nullptr;} @@ -203,31 +214,53 @@ void MapView3D::showGrid() { } +void MapView3D::setShowNavMesh(bool show) { + + this->showNavMesh = show; + if (!show) {update(); return;} + + // delete the previous grid (if any) + if (navMeshModel) {delete navMeshModel; navMeshModel = nullptr;} + + // build a new model + NavMeshModel* nm = new NavMeshModel(); + Floorplan::IndoorMap* im = getModel()->getMap(); + nm->rebuild(im); + + // remember + this->navMeshModel = nm; + + // update UI + update(); + +} + void MapView3D::draw() { - if (gridModel) { - - // show grid - gridRenderer->paintGL(gridModel->getGrid()); - - } else { + // solid floorplan parts + if (showFloorplan) { std::vector elements = getModel()->getVisibleElements(); - - // order: transparent last - auto func = [] (const MapModelElement* e1, const MapModelElement* e2) { - if (e1->getMV3D() == nullptr) {return false;} - if (e2->getMV3D() == nullptr) {return true;} - const bool e1t = e1->getMV3D()->isTransparent(); - const bool e2t = e2->getMV3D()->isTransparent(); - return e1t < e2t; - }; - - std::sort(elements.begin(), elements.end(), func); - - // show floorplan for (MapModelElement* el : elements) { - if (el->getMV3D()) {el->getMV3D()->paintGL();} + if (el->getMV3D() && !el->getMV3D()->isTransparent()) {el->getMV3D()->paintGL();} + } + + } + + if (showGrid) { + gridRenderer->paintGL(gridModel->getGrid()); + } + + if (showNavMesh) { + navMeshRenderer->paintGL(navMeshModel->getNavMesh(), this); + } + + // transparant floorplan parts + if (showFloorplan) { + + std::vector elements = getModel()->getVisibleElements(); + for (MapModelElement* el : elements) { + if (el->getMV3D() && el->getMV3D()->isTransparent()) {el->getMV3D()->paintGL();} } } diff --git a/mapview/3D/MapView3D.h b/mapview/3D/MapView3D.h index 7b46ed6..dc17011 100644 --- a/mapview/3D/MapView3D.h +++ b/mapview/3D/MapView3D.h @@ -9,6 +9,8 @@ class MapModel; class GridModel; class GridRenderer; +class NavMeshRenderer; +class NavMeshModel; class MapView3D : public QGLWidget { @@ -34,13 +36,27 @@ public: /** get the renderer to use for the grid */ GridRenderer* getGridRenderer() {return gridRenderer;} + /** get the renderer to use for the NavMesh */ + NavMeshRenderer* getNavMeshRenderer() {return navMeshRenderer;} + + +// /** show 3D rendered floorplan */ +// void showFloorplan(); + +// /** show 3D rendered grid derived from the floorplan */ +// void showGrid(); + +// /** show 3D rendered NavMesh derived from the floorplan */ +// void showNavMesh(); /** show 3D rendered floorplan */ - void showFloorplan(); + void setShowFloorplan(bool show); /** show 3D rendered grid derived from the floorplan */ - void showGrid(); + void setShowGrid(bool show); + /** show 3D rendered NavMesh derived from the floorplan */ + void setShowNavMesh(bool show); private: @@ -50,6 +66,13 @@ private: GridModel* gridModel = nullptr; GridRenderer* gridRenderer = nullptr; + NavMeshModel* navMeshModel = nullptr; + NavMeshRenderer* navMeshRenderer = nullptr; + + bool showFloorplan = true; + bool showGrid = false; + bool showNavMesh = false; + Point3 rot; Point3 center; Point3 scale; @@ -67,6 +90,7 @@ private: protected: + void initializeGL(); void paintGL(); void resizeGL(int width, int height); diff --git a/mapview/3DNavMesh/NavMeshModel.h b/mapview/3DNavMesh/NavMeshModel.h new file mode 100644 index 0000000..d68f174 --- /dev/null +++ b/mapview/3DNavMesh/NavMeshModel.h @@ -0,0 +1,85 @@ +#ifndef NAVMESHMODEL_H +#define NAVMESHMODEL_H + + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include "QNavMeshSettings.h" + +/** + * used for 3D NavMesh rendering + */ +class NavMeshModel { + +private: + + NM::NavMesh navMesh; + NM::NavMeshSettings settings; + Floorplan::IndoorMap* im; + +public: + + NavMeshModel() : navMesh() { + ; + } + + NM::NavMesh* getNavMesh() {return &navMesh;} + + + class Listener : public NM::NavMeshFactoryListener { + + private: + QDialog dlg; + QLabel* lbl1; + QProgressBar* bar1; + + public: + Listener() { + QVBoxLayout* lay = new QVBoxLayout(&dlg); + lbl1 = new QLabel(); lay->addWidget(lbl1); + bar1 = new QProgressBar(); lay->addWidget(bar1); + dlg.resize(350, 90); + dlg.setWindowTitle("NavMesh building"); + dlg.show(); + } + ~Listener() { + dlg.close(); + } + + void onNavMeshBuildUpdateMajor(const std::string& what) override { + lbl1->setText(what.c_str()); + QApplication::processEvents(); + } + void onNavMeshBuildUpdateMajor(const int cnt, const int cur) override { + bar1->setValue(cur*100/cnt); + QApplication::processEvents(); + } + + }; + + void rebuild(Floorplan::IndoorMap* im) { + + Listener l; + + QNavMeshSettings qs(&settings); + qs.exec(); + + if (qs.ok) { + NM::NavMeshFactory fac(&navMesh, settings); + fac.build(im, &l); + } + + } + +}; + + +#endif // NAVMESHMODEL_H diff --git a/mapview/3DNavMesh/NavMeshRenderer.h b/mapview/3DNavMesh/NavMeshRenderer.h new file mode 100644 index 0000000..c555368 --- /dev/null +++ b/mapview/3DNavMesh/NavMeshRenderer.h @@ -0,0 +1,172 @@ +#ifndef NAVMESHRENDERER_H +#define NAVMESHRENDERER_H + + + +#include +#include +#include +#include + +#include +#include + +//enum class GridRendererColorMode { +// SHOW_NODE_TYPE, +// SHOW_NODE_IMPORTANCE, +//}; + +class NavMeshRenderer { + +private: + + // settings + //GridRendererColorMode colorMode = GridRendererColorMode::SHOW_NODE_IMPORTANCE; + bool showEdges = false; + + struct Color { + float r,g,b; + Color() : r(1), g(0), b(0) {;} + Color(float r, float g, float b) : r(r), g(g), b(b) {;} + }; + + /** node color depending on the node's type. see ctor */ + Color colors[200]; + +public: + + /** ctor */ + NavMeshRenderer() { + + colors[GridNode::TYPE_FLOOR] = Color(0.4, 0.4, 0.4); + colors[GridNode::TYPE_STAIR] = Color(0,0,1); + colors[GridNode::TYPE_ELEVATOR] = Color(0,0,1); + colors[GridNode::TYPE_DOOR] = Color(0.0, 0.0, 0.0); + + colors[GridNode::TYPE_OUTDOOR] = Color(0.0, 0.5, 0.0); + + } + + +// void setNodeColorMode(const GridRendererColorMode mode) {this->colorMode = mode;} + void setShowEdges(const bool show) {this->showEdges = show;} + + + /** render the given grid using GL commands */ + void paintGL(NM::NavMesh* navMesh, QGLWidget* dst) { + + if (navMesh == nullptr) {return;} + +// QPainter qp; +// qp.begin(dst); + + glDisable(GL_LIGHTING); + + const float s = 2; + + + + glBegin(GL_TRIANGLES); + for (const NM::NavMeshTriangle* tria : *navMesh) { + +// // get the color to use +// switch(colorMode) { +// case GridRendererColorMode::SHOW_NODE_TYPE: { +// const Color c = colors[n.getType()]; +// glColor3f(c.r, c.g, c.b); +// break; +// } + +// case GridRendererColorMode::SHOW_NODE_IMPORTANCE: { +// const float xx = n.navImportance - 0.6; +// glColor3f(xx, xx, xx); +// break; +// } + +// } + + switch (tria->getType()) { + case (int) NM::NavMeshType::FLOOR_INDOOR: glColor3f(0.8, 0.8, 0.8); break; + case (int) NM::NavMeshType::FLOOR_OUTDOOR: glColor3f(0.1, 0.8, 0.1); break; + case (int) NM::NavMeshType::DOOR: glColor3f(0.7, 0.7, 0.8); break; + case (int) NM::NavMeshType::STAIR_LEVELED: glColor3f(0.5, 0.5, 0.5); break; + case (int) NM::NavMeshType::STAIR_SKEWED: glColor3f(0.6, 0.6, 0.6); break; + } + + glVertex3f(tria->getP1().x, tria->getP1().z, tria->getP1().y); + glVertex3f(tria->getP2().x, tria->getP2().z, tria->getP2().y); + glVertex3f(tria->getP3().x, tria->getP3().z, tria->getP3().y); + + } + glEnd(); + + + glEnable(GL_MULTISAMPLE); + //glEnable(GL_LINE_SMOOTH); + + glBegin(GL_LINES); + //glColor3f(0.2,0.2,0.2); + for (const NM::NavMeshTriangle* tria : *navMesh) { + + switch (tria->getType()) { + case (int) NM::NavMeshType::FLOOR_INDOOR: glColor3f(0.6, 0.6, 0.6); break; + case (int) NM::NavMeshType::FLOOR_OUTDOOR: glColor3f(0.0, 0.6, 0.0); break; + case (int) NM::NavMeshType::DOOR: glColor3f(0.5, 0.5, 0.6); break; + case (int) NM::NavMeshType::STAIR_LEVELED: glColor3f(0.4, 0.4, 0.4); break; + case (int) NM::NavMeshType::STAIR_SKEWED: glColor3f(0.4, 0.4, 0.4); break; + } + + glVertex3f(tria->getP1().x, tria->getP1().z+0.01, tria->getP1().y); + glVertex3f(tria->getP2().x, tria->getP2().z+0.01, tria->getP2().y); + + glVertex3f(tria->getP2().x, tria->getP2().z+0.01, tria->getP2().y); + glVertex3f(tria->getP3().x, tria->getP3().z+0.01, tria->getP3().y); + + glVertex3f(tria->getP3().x, tria->getP3().z+0.01, tria->getP3().y); + glVertex3f(tria->getP1().x, tria->getP1().z+0.01, tria->getP1().y); + +// glBegin(GL_LINE_LOOP); +// glVertex3f(tria->getP1().x, tria->getP1().z+0.01, tria->getP1().y); +// glVertex3f(tria->getP2().x, tria->getP2().z+0.01, tria->getP2().y); +// glVertex3f(tria->getP3().x, tria->getP3().z+0.01, tria->getP3().y); +// glEnd(); + } + + glEnd(); + + glEnable(GL_LIGHTING); + + +// qp.drawText(20,20, "sdfsdkflsdfjasfklsdklfsdklfsdf"); +// qp.drawText(20,-20, "sdfsdkflsdfjasfklsdklfsdklfsdf"); +// qp.drawText(0.5,0.5, "sdfsdkflsdfjasfklsdklfsdklfsdf"); +// qp.end(); + +// renderText(1,1,1, "123"); + + const QString str1 = "Triangles: " + QString::number(navMesh->getNumTriangles()); + const QString str2 = "Size: ~" + QString::number(navMesh->getNumTriangles() * sizeof(NM::NavMeshTriangle) / 1024) + " kB"; + + glColor3f(0.0, 0.0, 0.0); + dst->renderText(20,20, str1); + dst->renderText(20,35, str2); + + // dst->renderText(0,0, "2342342342342423423423423423423432"); + // dst->renderText(0.1, 0.1, 0.1, "lsdfsdfsdfsdfsdfsdfsdfol"); + } + +// std::vector lint() { +// std::vector vec; +// lintStair(vec); +// return vec; +// } + +// void lintStair(std::vector& vec) { +// for (MyNode& n1 : *grid) { +// if (n1.getNumNeighbors() <= 5) { vec.push_back(n1);} +// } +// } + +}; + +#endif // NAVMESHRENDERER_H diff --git a/mapview/3DNavMesh/QNavMeshSettings.cpp b/mapview/3DNavMesh/QNavMeshSettings.cpp new file mode 100644 index 0000000..106e733 --- /dev/null +++ b/mapview/3DNavMesh/QNavMeshSettings.cpp @@ -0,0 +1,87 @@ +#include "QNavMeshSettings.h" + +#include + +#include +#include +#include +#include +#include + +QNavMeshSettings::QNavMeshSettings(NM::NavMeshSettings* settings, QWidget* parent) : QDialog(parent) { + + QGridLayout* lay = new QGridLayout(this); + this->setLayout(lay); + int row = 0; + + this->setWindowTitle("NavMesh Settings"); + this->setMinimumWidth(350); + + // MAX QUALITY + { + lay->addWidget(new QLabel("smallest element"), row, 0); + QLabel* lblQuality = new QLabel(""); + lay->addWidget(lblQuality, row, 2); + QSlider* sldQuality = new QSlider(Qt::Orientation::Horizontal); sldQuality->setMinimum(10); sldQuality->setMaximum(30); + connect(sldQuality, &QSlider::valueChanged, [settings, sldQuality, lblQuality] () { + settings->maxQuality_m = sldQuality->value() / 100.0f; + lblQuality->setText(QString("%1 m").arg(settings->maxQuality_m, 5, 'f', 2, 0)); + }); + sldQuality->setValue(settings->maxQuality_m * 100.0f); + lay->addWidget(sldQuality, row, 1); + ++row; + } + + // AGENT HEIGHT + { + lay->addWidget(new QLabel("agent height"), row, 0); + QLabel* lblHeight = new QLabel(""); + lay->addWidget(lblHeight, row, 2); + QSlider* sldHeight = new QSlider(Qt::Orientation::Horizontal); sldHeight->setMinimum(10); sldHeight->setMaximum(200); + connect(sldHeight, &QSlider::valueChanged, [settings, sldHeight, lblHeight] () { + settings->agentHeight = sldHeight->value() / 100.0f; + lblHeight->setText(QString("%1 m").arg(settings->agentHeight, 5, 'f', 2, 0)); + }); + sldHeight->setValue(settings->agentHeight * 100.0f); + lay->addWidget(sldHeight, row, 1); + ++row; + } + + // AGENT RADIUS + { + lay->addWidget(new QLabel("agent radius"), row, 0); + QLabel* lblRadius = new QLabel(""); + lay->addWidget(lblRadius, row, 2); + QSlider* sldRadius = new QSlider(Qt::Orientation::Horizontal); sldRadius->setMinimum(5); sldRadius->setMaximum(60); + connect(sldRadius, &QSlider::valueChanged, [settings, sldRadius, lblRadius] () { + settings->agentRadius = sldRadius->value() / 100.0f; + lblRadius->setText(QString("%1 m").arg(settings->agentRadius, 5, 'f', 2, 0)); + }); + sldRadius->setValue(settings->agentRadius * 100.0f); + lay->addWidget(sldRadius, row, 1); + ++row; + } + + + // MAX EDGE LENGTH + { + lay->addWidget(new QLabel("max edge length"), row, 0); + QLabel* lblMaxEdgeLength = new QLabel(""); + lay->addWidget(lblMaxEdgeLength, row, 2); + QSlider* sdlMaxEdgeLength = new QSlider(Qt::Orientation::Horizontal); sdlMaxEdgeLength->setMinimum(300); sdlMaxEdgeLength->setMaximum(2000); + connect(sdlMaxEdgeLength, &QSlider::valueChanged, [settings, sdlMaxEdgeLength, lblMaxEdgeLength] () { + settings->edgeMaxLen = sdlMaxEdgeLength->value() / 100.0f; + lblMaxEdgeLength->setText(QString("%1 m").arg(settings->edgeMaxLen, 5, 'f', 2, 0)); + }); + sdlMaxEdgeLength->setValue(settings->edgeMaxLen * 100.0f); + lay->addWidget(sdlMaxEdgeLength, row, 1); + ++row; + } + + QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::StandardButton::Ok | QDialogButtonBox::StandardButton::Close); + lay->addWidget(box, row, 0, 1, 3); + + connect(box, &QDialogButtonBox::accepted, [&] () {ok = true; close();}); + connect(box, &QDialogButtonBox::rejected, [&] () {ok = false; close();}); + +} diff --git a/mapview/3DNavMesh/QNavMeshSettings.h b/mapview/3DNavMesh/QNavMeshSettings.h new file mode 100644 index 0000000..d22eb5f --- /dev/null +++ b/mapview/3DNavMesh/QNavMeshSettings.h @@ -0,0 +1,24 @@ +#ifndef QNAVMESHSETTINGS_H +#define QNAVMESHSETTINGS_H + +#include +#include + +namespace NM { + class NavMeshSettings; +} + +class QNavMeshSettings : public QDialog { + + Q_OBJECT + + +public: + + QNavMeshSettings(NM::NavMeshSettings* settings, QWidget* parent = nullptr); + + bool ok = false; + +}; + +#endif // QNAVMESHSETTINGS_H diff --git a/mapview/model/MMFloor.h b/mapview/model/MMFloor.h index daad948..602de36 100644 --- a/mapview/model/MMFloor.h +++ b/mapview/model/MMFloor.h @@ -58,6 +58,11 @@ public: /** get the underlying model */ Floorplan::Floor& getFloor() {return *floor;} + virtual void setVisible(const bool visible) override { + floor->enabled = visible; + MapLayer::setVisible(visible); + } + std::string getLayerName() const override {return floor->name;} diff --git a/mapview/model/MapLayer.h b/mapview/model/MapLayer.h index 40333da..0e7e69a 100644 --- a/mapview/model/MapLayer.h +++ b/mapview/model/MapLayer.h @@ -107,7 +107,7 @@ public: bool isVisible() const {return visible;} /** make this layer visible */ - void setVisible(const bool visible) { + virtual void setVisible(const bool visible) { this->visible = visible; onVisibilityChanged(visible); }