refactoring
wireframe display worked on 3d-model display
This commit is contained in:
@@ -56,6 +56,15 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
|
||||
emit update();
|
||||
});
|
||||
|
||||
QPushButton* btnWireframe = new QPushButton(UIHelper::getIcon("wireframe"), "", this);
|
||||
btnWireframe->setCheckable(true);
|
||||
btnWireframe->setStyleSheet(style);
|
||||
btnWireframe->setGeometry(16, 16+8+32+8+32, 32, 32);
|
||||
connect(btnWireframe, &QPushButton::clicked, [this] () {
|
||||
useWireframe = !useWireframe;
|
||||
emit update();
|
||||
});
|
||||
|
||||
QPushButton* btnGrid = new QPushButton(UIHelper::getIcon("grid"), "", this);
|
||||
btnGrid->setCheckable(true);
|
||||
btnGrid->setChecked(false);
|
||||
@@ -74,6 +83,7 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
|
||||
emit onShow3DNavMesh(btnNavMesh->isChecked());
|
||||
});
|
||||
|
||||
|
||||
// android
|
||||
setAttribute(Qt::WA_AcceptTouchEvents, true);
|
||||
grabGesture(Qt::PanGesture);
|
||||
@@ -81,7 +91,7 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) {
|
||||
|
||||
auto format = QSurfaceFormat();
|
||||
//format.setVersion(4,3);
|
||||
format.setSamples(4);
|
||||
format.setSamples(2);
|
||||
//format.setProfile(QSurfaceFormat::CoreProfile);
|
||||
|
||||
setFormat(format);
|
||||
@@ -298,8 +308,8 @@ void MapView3D::draw() {
|
||||
rs.shader->setViewMatrix(V);
|
||||
rs.shader->setProjectionMatrix(P);
|
||||
|
||||
if (floorplanRenderer && floorplanRendererModel) {
|
||||
floorplanRenderer->renderSolid(rs, floorplanRendererModel->getTriaSolid() );
|
||||
if (showFloorplan && floorplanRendererModel) {
|
||||
floorplanRenderer->renderSolid(rs, floorplanRendererModel->getTriaSolid(), useWireframe );
|
||||
}
|
||||
|
||||
// // solid floorplan parts
|
||||
@@ -330,8 +340,8 @@ void MapView3D::draw() {
|
||||
|
||||
// }
|
||||
|
||||
if (floorplanRenderer && floorplanRendererModel) {
|
||||
floorplanRenderer->renderTransp(rs, floorplanRendererModel->getTriaTransp() );
|
||||
if (showFloorplan && floorplanRendererModel) {
|
||||
floorplanRenderer->renderTransp(rs, floorplanRendererModel->getTriaTransp(), useWireframe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class MapView3D : public QOpenGLWidget {
|
||||
Q_OBJECT
|
||||
|
||||
bool usePerspectiveProjection = false;
|
||||
bool useWireframe = false;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -27,25 +27,34 @@ public:
|
||||
}
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void renderSolid(const RenderSettings& rs, const RenderTriangle& rt) {
|
||||
void renderSolid(const RenderSettings& rs, const RenderTriangle& rt, bool wireframe) {
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
rs.shader->setVertices(rt.getVertices().data());
|
||||
rs.shader->setNormals(rt.getNormals().data());
|
||||
rs.shader->setVertexColor(rt.getRGBA().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.getVertices().size()/3);
|
||||
rs.shader->setVertices(rt.getVertices());
|
||||
rs.shader->setNormals(rt.getNormals());
|
||||
rs.shader->setVertexColor(rt.getRGBA());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.count());
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
if (wireframe) {
|
||||
RenderTriangle rt2 = rt.toWireframe(false);
|
||||
rs.shader->setColor(0,0,0,128);
|
||||
rs.shader->setVertices(rt2.getVertices());
|
||||
//rs.shader->setVertexColor(rt2.getRGBA());
|
||||
glDrawArrays(GL_LINES, 0, rt2.count());
|
||||
rs.shader->unsetVertices();
|
||||
//rs.shader->unsetVertexColor();
|
||||
}
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void renderTransp(const RenderSettings& rs, const RenderTriangle& rt) {
|
||||
void renderTransp(const RenderSettings& rs, const RenderTriangle& rt, bool wireframe) {
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -53,14 +62,24 @@ public:
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
rs.shader->setVertices(rt.getVertices().data());
|
||||
rs.shader->setNormals(rt.getNormals().data());
|
||||
rs.shader->setVertexColor(rt.getRGBA().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.getVertices().size()/3);
|
||||
rs.shader->setVertices(rt.getVertices());
|
||||
rs.shader->setNormals(rt.getNormals());
|
||||
rs.shader->setVertexColor(rt.getRGBA());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.count());
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
if (wireframe) {
|
||||
RenderTriangle rt2 = rt.toWireframe(false);
|
||||
rs.shader->setColor(0,0,0,128);
|
||||
rs.shader->setVertices(rt2.getVertices());
|
||||
//rs.shader->setVertexColor(rt2.getRGBA());
|
||||
glDrawArrays(GL_LINES, 0, rt2.count());
|
||||
rs.shader->unsetVertices();
|
||||
//rs.shader->unsetVertexColor();
|
||||
}
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
@@ -7,56 +7,71 @@
|
||||
|
||||
class RenderTriangle {
|
||||
|
||||
std::vector<float> vertices;
|
||||
std::vector<float> normals;
|
||||
std::vector<float> rgba;
|
||||
struct Vertex{
|
||||
float x,y,z;
|
||||
Vertex(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Normal {
|
||||
float x,y,z;
|
||||
Normal(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||||
} __attribute__((packed));
|
||||
|
||||
struct RGBA {
|
||||
float r,g,b,a;
|
||||
RGBA(const float r, const float g, const float b, const float a) : r(r), g(g), b(b), a(a) {;}
|
||||
} __attribute__((packed));
|
||||
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<Normal> normals;
|
||||
std::vector<RGBA> rgba;
|
||||
|
||||
public:
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
vertices.push_back(Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
vertices.push_back(Vertex(p3.x, p3.y, p3.z));
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
vertices.push_back(Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
vertices.push_back(Vertex(p3.x, p3.y, p3.z));
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
vertices.push_back(Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
vertices.push_back(Vertex(p3.x, p3.y, p3.z));
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
normals.push_back(Normal(n.x, n.y, n.z));
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void addLine(Point3 p1, Point3 p2, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.push_back( Vertex(p1.x, p1.y, p1.z));
|
||||
vertices.push_back(Vertex(p2.x, p2.y, p2.z));
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.push_back( RGBA(r,g,b,a));
|
||||
rgba.push_back(RGBA(r,g,b,a));
|
||||
|
||||
}
|
||||
|
||||
@@ -66,11 +81,49 @@ public:
|
||||
rgba.clear();
|
||||
}
|
||||
|
||||
const std::vector<float>& getVertices() const {return vertices;}
|
||||
const float* getVertices() const {return (float*) vertices.data();}
|
||||
|
||||
const std::vector<float>& getNormals() const {return normals;}
|
||||
const float* getNormals() const {return (float*) normals.data();}
|
||||
|
||||
const std::vector<float>& getRGBA() const {return rgba;}
|
||||
const float* getRGBA() const {return (float*) rgba.data();}
|
||||
|
||||
size_t count() const {return vertices.size();}
|
||||
|
||||
RenderTriangle toWireframe(const bool withVertexColors) const {
|
||||
|
||||
RenderTriangle res;
|
||||
|
||||
for (size_t i = 0; i < vertices.size(); i += 3) {
|
||||
|
||||
res.vertices.push_back(vertices[i+0]);
|
||||
res.vertices.push_back(vertices[i+1]);
|
||||
|
||||
res.vertices.push_back(vertices[i+1]);
|
||||
res.vertices.push_back(vertices[i+2]);
|
||||
|
||||
res.vertices.push_back(vertices[i+2]);
|
||||
res.vertices.push_back(vertices[i+0]);
|
||||
|
||||
}
|
||||
|
||||
if (withVertexColors) {
|
||||
for (size_t i = 0; i < rgba.size(); i += 3) {
|
||||
|
||||
res.rgba.push_back(rgba[i+0]);
|
||||
res.rgba.push_back(rgba[i+1]);
|
||||
|
||||
res.rgba.push_back(rgba[i+1]);
|
||||
res.rgba.push_back(rgba[i+2]);
|
||||
|
||||
res.rgba.push_back(rgba[i+2]);
|
||||
res.rgba.push_back(rgba[i+0]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user