feat: Render OpenCASCADE faces in viewport
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -30,6 +30,13 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <BRepMesh_IncrementalMesh.hxx>
|
||||||
|
#include <TopExp_Explorer.hxx>
|
||||||
|
#include <TopoDS.hxx>
|
||||||
|
#include <TopoDS_Face.hxx>
|
||||||
|
#include <Poly_Triangulation.hxx>
|
||||||
|
#include <BRep_Tool.hxx>
|
||||||
|
|
||||||
struct PntComparator {
|
struct PntComparator {
|
||||||
bool operator()(const gp_Pnt& a, const gp_Pnt& b) const {
|
bool operator()(const gp_Pnt& a, const gp_Pnt& b) const {
|
||||||
// A tolerance is needed for floating point comparisons
|
// A tolerance is needed for floating point comparisons
|
||||||
@@ -649,6 +656,44 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw faces
|
||||||
|
if (!sketch->shape().IsNull()) {
|
||||||
|
BRepMesh_IncrementalMesh(sketch->shape(), 0.1); // Linear deflection
|
||||||
|
|
||||||
|
QVector<GLfloat> faceVertices;
|
||||||
|
TopExp_Explorer explorer(sketch->shape(), TopAbs_FACE);
|
||||||
|
for (; explorer.More(); explorer.Next()) {
|
||||||
|
TopoDS_Face face = TopoDS::Face(explorer.Current());
|
||||||
|
TopLoc_Location location;
|
||||||
|
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(face, location);
|
||||||
|
|
||||||
|
if (!triangulation.IsNull()) {
|
||||||
|
const TColgp_Array1OfPnt& nodes = triangulation->Nodes();
|
||||||
|
const Poly_Array1OfTriangle& triangles = triangulation->Triangles();
|
||||||
|
|
||||||
|
for (int i = 1; i <= triangles.Length(); ++i) {
|
||||||
|
const Poly_Triangle& triangle = triangles(i);
|
||||||
|
gp_Pnt p1 = nodes(triangle.Value(1)).Transformed(location);
|
||||||
|
gp_Pnt p2 = nodes(triangle.Value(2)).Transformed(location);
|
||||||
|
gp_Pnt p3 = nodes(triangle.Value(3)).Transformed(location);
|
||||||
|
faceVertices << p1.X() << p1.Y() << p1.Z();
|
||||||
|
faceVertices << p2.X() << p2.Y() << p2.Z();
|
||||||
|
faceVertices << p3.X() << p3.Y() << p3.Z();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!faceVertices.isEmpty()) {
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
m_shaderProgram->setUniformValue(m_colorLoc, QVector4D(0.5f, 0.5f, 1.0f, 0.5f));
|
||||||
|
m_vbo.bind();
|
||||||
|
m_vbo.allocate(faceVertices.constData(), faceVertices.size() * sizeof(GLfloat));
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, faceVertices.size() / 3);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user