fix: Correct sketch face rendering, orientation, and complex wire generation
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <ShapeAnalysis_FreeBounds.hxx>
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
@@ -113,24 +114,25 @@ void SketchFeature::buildShape()
|
||||
}
|
||||
|
||||
if (!lineEdges.isEmpty()) {
|
||||
BRepBuilderAPI_MakeWire wireBuilder;
|
||||
TopoDS_Compound compound;
|
||||
BRep_Builder builder;
|
||||
builder.MakeCompound(compound);
|
||||
for (const auto& edge : lineEdges) {
|
||||
wireBuilder.Add(edge);
|
||||
builder.Add(compound, edge);
|
||||
}
|
||||
if (wireBuilder.IsDone()) {
|
||||
TopoDS_Shape wiresShape = wireBuilder.Shape();
|
||||
TopExp_Explorer explorer(wiresShape, TopAbs_WIRE);
|
||||
|
||||
ShapeAnalysis_FreeBounds freeBounds(compound, 1e-6, Standard_True);
|
||||
TopoDS_Compound closedWires = freeBounds.GetClosedWires();
|
||||
|
||||
TopExp_Explorer explorer(closedWires, TopAbs_WIRE);
|
||||
for (; explorer.More(); explorer.Next()) {
|
||||
TopoDS_Wire wire = TopoDS::Wire(explorer.Current());
|
||||
if (wire.Closed()) {
|
||||
BRepBuilderAPI_MakeFace faceBuilder(wire);
|
||||
if (faceBuilder.IsDone()) {
|
||||
faces.append(faceBuilder.Face());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (faces.isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -544,11 +544,11 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
||||
switch (sketch->plane()) {
|
||||
case SketchFeature::SketchPlane::XY:
|
||||
u_axis = QVector3D(1, 0, 0);
|
||||
v_axis = QVector3D(0, 0, 1);
|
||||
v_axis = QVector3D(0, 1, 0);
|
||||
break;
|
||||
case SketchFeature::SketchPlane::XZ:
|
||||
u_axis = QVector3D(1, 0, 0);
|
||||
v_axis = QVector3D(0, 1, 0);
|
||||
v_axis = QVector3D(0, 0, 1);
|
||||
break;
|
||||
case SketchFeature::SketchPlane::YZ:
|
||||
u_axis = QVector3D(0, 1, 0);
|
||||
@@ -574,10 +574,10 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
||||
gp_Pnt p2, p4;
|
||||
if (sketch->plane() == SketchFeature::SketchPlane::XY) {
|
||||
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||
p4.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||
} else if (sketch->plane() == SketchFeature::SketchPlane::XZ) {
|
||||
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||
p4.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||
} else if (sketch->plane() == SketchFeature::SketchPlane::YZ) {
|
||||
p2.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||
@@ -664,6 +664,7 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
||||
|
||||
// Draw faces
|
||||
if (!sketch->shape().IsNull()) {
|
||||
glDisable(GL_CULL_FACE);
|
||||
BRepMesh_IncrementalMesh(sketch->shape(), 0.1, Standard_False, 0.5, Standard_True); // Linear deflection, compute normals
|
||||
|
||||
QVector<GLfloat> faceData;
|
||||
@@ -731,6 +732,7 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
||||
glDrawArrays(GL_TRIANGLES, 0, faceData.size() / 6);
|
||||
m_shaderProgram->bind(); // rebind simple shader for subsequent draws
|
||||
}
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
@@ -787,6 +789,9 @@ void ViewportWidget::drawSelectionPlanes()
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
m_vbo.bind();
|
||||
m_shaderProgram->enableAttributeArray(0);
|
||||
m_shaderProgram->setAttributeBuffer(0, GL_FLOAT, 0, 3, 0);
|
||||
m_shaderProgram->disableAttributeArray(1);
|
||||
QVector<GLfloat> vertices;
|
||||
|
||||
auto drawPlane = [&](const QVector<GLfloat>& quadVerts, bool highlighted) {
|
||||
|
||||
Reference in New Issue
Block a user