re-added grid-rendering to the editor
rebuild grid/navMesh 3D data only if needed
This commit is contained in:
@@ -24,6 +24,7 @@ private:
|
||||
NM::NavMesh<NM::NavMeshTriangle> navMesh;
|
||||
NM::NavMeshSettings settings;
|
||||
Floorplan::IndoorMap* im;
|
||||
int buildID = 0;
|
||||
|
||||
public:
|
||||
|
||||
@@ -65,6 +66,10 @@ public:
|
||||
|
||||
};
|
||||
|
||||
int getBuildID() const {
|
||||
return buildID;
|
||||
}
|
||||
|
||||
void rebuild(Floorplan::IndoorMap* im) {
|
||||
|
||||
Listener l;
|
||||
@@ -77,6 +82,8 @@ public:
|
||||
fac.build(im, &l);
|
||||
}
|
||||
|
||||
buildID = rand();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
90
mapview/3D/navMesh/NavMeshRenderer.cpp
Normal file
90
mapview/3D/navMesh/NavMeshRenderer.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "NavMeshRenderer.h"
|
||||
#include "NavMeshModel.h"
|
||||
|
||||
NavMeshRenderer::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 NavMeshRenderer::rebuildIfNeeded(NavMeshModel* model) {
|
||||
|
||||
// rebuild needed?
|
||||
if (lastBuildID == model->getBuildID()) {return;}
|
||||
lastBuildID = model->getBuildID();
|
||||
|
||||
// get the mesh
|
||||
NM::NavMesh<NM::NavMeshTriangle>* navMesh = model->getNavMesh();
|
||||
|
||||
// clear previous
|
||||
triangles.clear();
|
||||
outlines.clear();
|
||||
|
||||
// create triangles
|
||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||
|
||||
Point3 color;
|
||||
|
||||
switch (tria->getType()) {
|
||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.8, 0.8, 0.8); break;
|
||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.1, 0.8, 0.1); break;
|
||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.7, 0.7, 0.8); break;
|
||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.5, 0.5, 0.5); break;
|
||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.6, 0.6, 0.6); break;
|
||||
}
|
||||
|
||||
triangles.addTriangle(tria->getP1(), tria->getP3(), tria->getP2(), Point3(0,0,1), color.x, color.y, color.z, 1.0f);
|
||||
|
||||
}
|
||||
|
||||
// create outlines
|
||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||
|
||||
Point3 color;
|
||||
|
||||
switch (tria->getType()) {
|
||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.6, 0.6, 0.6); break;
|
||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.0, 0.6, 0.0); break;
|
||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.5, 0.5, 0.6); break;
|
||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.4, 0.4, 0.4); break;
|
||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.4, 0.4, 0.4); break;
|
||||
}
|
||||
|
||||
const float o = 0.001f;
|
||||
outlines.addLine(tria->getP1(), tria->getP2(), color.x, color.y, color.z, 1);
|
||||
outlines.addLine(tria->getP2(), tria->getP3(), color.x, color.y, color.z, 1);
|
||||
outlines.addLine(tria->getP3(), tria->getP1(), color.x, color.y, color.z, 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NavMeshRenderer::render(const RenderSettings& rs, NavMeshModel* model) {
|
||||
|
||||
if (model == nullptr) {return;}
|
||||
|
||||
rebuildIfNeeded(model);
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
rs.shader->setVertices(triangles.getVertices().data());
|
||||
rs.shader->setVertexColor(triangles.getRGBA().data());
|
||||
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, triangles.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
rs.shader->setVertices(outlines.getVertices().data());
|
||||
rs.shader->setVertexColor(outlines.getRGBA().data());
|
||||
rs.funcs->glDrawArrays(GL_LINES, 0, outlines.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "../misc/Shader.h"
|
||||
#include "../misc/TriangleData.h"
|
||||
|
||||
class NavMeshModel;
|
||||
|
||||
class NavMeshRenderer {
|
||||
|
||||
private:
|
||||
@@ -30,22 +32,17 @@ private:
|
||||
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];
|
||||
// /** node color depending on the node's type. see ctor */
|
||||
// Color colors[200];
|
||||
|
||||
TriangleData triangles;
|
||||
TriangleData outlines;
|
||||
int lastBuildID = 0; // to check whether the model has changed
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
NavMeshRenderer();
|
||||
|
||||
|
||||
// void setNodeColorMode(const GridRendererColorMode mode) {this->colorMode = mode;}
|
||||
@@ -53,105 +50,11 @@ public:
|
||||
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void render(const RenderSettings& rs, NM::NavMesh<NM::NavMeshTriangle>* navMesh, QOpenGLWidget* dst) {
|
||||
void render(const RenderSettings& rs, NavMeshModel* model);
|
||||
|
||||
if (navMesh == nullptr) {return;}
|
||||
private:
|
||||
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
TriangleData data;
|
||||
|
||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||
|
||||
Point3 color;
|
||||
|
||||
switch (tria->getType()) {
|
||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.8, 0.8, 0.8); break;
|
||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.1, 0.8, 0.1); break;
|
||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.7, 0.7, 0.8); break;
|
||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.5, 0.5, 0.5); break;
|
||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.6, 0.6, 0.6); break;
|
||||
}
|
||||
|
||||
data.addTriangle(tria->getP1(), tria->getP3(), tria->getP2(), Point3(0,0,1), color.x, color.y, color.z, 1.0f);
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z});
|
||||
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z});
|
||||
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z});
|
||||
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
|
||||
}
|
||||
|
||||
rs.shader->setVertices(data.getVertices().data());
|
||||
rs.shader->setVertexColor(data.getRGBA().data());
|
||||
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
data.clear();
|
||||
|
||||
|
||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||
|
||||
Point3 color;
|
||||
|
||||
switch (tria->getType()) {
|
||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.6, 0.6, 0.6); break;
|
||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.0, 0.6, 0.0); break;
|
||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.5, 0.5, 0.6); break;
|
||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.4, 0.4, 0.4); break;
|
||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.4, 0.4, 0.4); break;
|
||||
}
|
||||
|
||||
const float o = 0.001f;
|
||||
data.addLine(tria->getP1(), tria->getP2(), color.x, color.y, color.z, 1);
|
||||
data.addLine(tria->getP2(), tria->getP3(), color.x, color.y, color.z, 1);
|
||||
data.addLine(tria->getP3(), tria->getP1(), color.x, color.y, color.z, 1);
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
||||
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
||||
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
||||
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
||||
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
|
||||
}
|
||||
|
||||
rs.shader->setVertices(data.getVertices().data());
|
||||
rs.shader->setVertexColor(data.getRGBA().data());
|
||||
rs.funcs->glDrawArrays(GL_LINES, 0, data.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
|
||||
// std::vector<MyNode> lint() {
|
||||
// std::vector<MyNode> vec;
|
||||
// lintStair(vec);
|
||||
// return vec;
|
||||
// }
|
||||
|
||||
// void lintStair(std::vector<MyNode>& vec) {
|
||||
// for (MyNode& n1 : *grid) {
|
||||
// if (n1.getNumNeighbors() <= 5) { vec.push_back(n1);}
|
||||
// }
|
||||
// }
|
||||
void rebuildIfNeeded(NavMeshModel* model);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user