- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I get "Failure" result on a very simple BRepBuilder example, when I try to build a (4-sided triangle pyramid) Tetrahedron. I know about TessellatedShapeBuilder, but it fails for a quite complex object here, so I hope to bypass this with the BREP.
public class Test{
public Test(){}
// Keep track of already created edges and their orientation
struct BrepEdge {
public BRepBuilderGeometryId id;
public XYZ p1, p2;
}
List<BrepEdge> brep_edges = new List<BrepEdge>();
// add edge to face loop
void AddEdgeToBREP( BRepBuilder brep, BRepBuilderGeometryId loop, XYZ a, XYZ b) {
foreach(var be in brep_edges) {
// ab is p1-p2
if(be.p1.DistanceTo(a) < 1e-7 && be.p2.DistanceTo(b) < 1e-7) { brep.AddCoEdge(loop, be.id, false);return; }
// ab is p2-p1 (reversed edge)
if(be.p1.DistanceTo(b) < 1e-7 && be.p2.DistanceTo(a) < 1e-7) { brep.AddCoEdge(loop, be.id, true); return; }
}
// must create a new edge
BRepBuilderGeometryId edge = brep.AddEdge(BRepBuilderEdgeGeometry.Create(a, b));
brep.AddCoEdge(loop, edge, false);
var bed = new BrepEdge();
bed.p1 = a;
bed.p2 = b;
bed.id = edge;
brep_edges.Add(bed);
}
// add triangle face to solid
private void AddTriangleToBREP( BRepBuilder brep, XYZ a, XYZ b, XYZ c ) {
Plane plane = Plane.CreateByThreePoints(a, b, c);
BRepBuilderGeometryId face = brep.AddFace(BRepBuilderSurfaceGeometry.Create(plane, null), true);
var loop = brep.AddLoop(face);
AddEdgeToBREP(brep, loop, a, b);
AddEdgeToBREP(brep, loop, b, c);
AddEdgeToBREP(brep, loop, c, a);
brep.FinishLoop(loop);
brep.FinishFace(face);
}
///////////////////////////////////////////////////////////////////////////
public void run() {
BRepBuilder brep = new BRepBuilder(BRepType.Solid);
var points = new List<XYZ>(4);
points.Add(new XYZ(0, 0, 0)); // 0 origin
points.Add(new XYZ(1, 0, 0)); // 1 right
points.Add(new XYZ(0, 1, 0)); // 2 back
points.Add(new XYZ(0, 0, 1)); // 3 top
AddTriangleToBREP(brep, points[2], points[1], points[0]); // bottom face
AddTriangleToBREP(brep, points[0], points[1], points[3]); // front face
AddTriangleToBREP(brep, points[1], points[2], points[3]); // diagonal face
AddTriangleToBREP(brep, points[2], points[0], points[3]); // left face
var outcome = brep.Finish(); // <<<<< Failure
// throws: "This BRepBuilder object hasn't completed building data or was unsuccessful building it.
// Built Geometry is unavailable. In order to access the built Geometry,
// Finish() must be called first. That will set the state to completed."
var res = brep.GetResult();
}
}
Solved! Go to Solution.
Link copied