re-added grid-rendering to the editor
rebuild grid/navMesh 3D data only if needed
This commit is contained in:
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();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user