//-------------------------------------------------------------------------------------------------- public static void UpdateSolidOrientation(TopoDS_Shape solid) { var classifier = new BRepClass3d_SolidClassifier(solid); classifier.PerformInfinitePoint(Precision.Confusion()); if (classifier.State() == TopAbs_State.TopAbs_IN) { solid.Reverse(); } }
//-------------------------------------------------------------------------------------------------- public static TopoDS_Solid MakeSolid(TopoDS_Shell shell, bool correctOrientation) { var builder = new BRep_Builder(); var solid = new TopoDS_Solid(); builder.MakeSolid(solid); builder.Add(solid, shell); if (correctOrientation) { var classifier = new BRepClass3d_SolidClassifier(solid); classifier.PerformInfinitePoint(Precision.Confusion()); if (classifier.State() == TopAbs_State.TopAbs_IN) { solid = new TopoDS_Solid(); builder.MakeSolid(solid); builder.Add(solid, shell.Reversed()); } } return(solid); }
//-------------------------------------------------------------------------------------------------- bool _DoOffset(MakeContext context) { if (_Offset <= 0) { return(false); } // Move neutral plane var newPlane = context.NeutralPlane.Translated(context.Direction.ToVec().Multiplied(_Offset)); // Create section edge var faceOfPlane = new BRepBuilderAPI_MakeFace(new Geom_Plane(newPlane), Precision.Confusion()).Shape(); var section = new BRepAlgoAPI_Section(context.Face, faceOfPlane); section.Build(); if (!section.IsDone()) { Messages.Warning("The offset can not be performed, section operation failed."); return(false); } var newEdge = section.Shape().Edges().FirstOrDefault(); if (!section.IsDone() || newEdge == null) { Messages.Warning("The offset value seems to be out of range."); return(false); } if (context.ReversedFaceSense) { newEdge.Orientation(TopAbs_Orientation.TopAbs_REVERSED); } // Split face with section edge var splitShape = new BRepFeat_SplitShape(context.Source); splitShape.Add(newEdge, context.Face); splitShape.Build(); if (!splitShape.IsDone()) { Messages.Warning("The offset can not be performed, the face split operation failed."); return(false); } var newShape = splitShape.Shape(); var newFace = splitShape.DirectLeft().First().ToFace(); // Reduce continuity of new edge to C0 to allow the draft algo to make a sharp corner var(face1, face2) = EdgeAlgo.FindAdjacentFaces(newShape, newEdge); if (face1 == null || face2 == null) { Messages.Warning("The offset can not be performed, invalid face count after split operation."); return(false); } var builder = new BRep_Builder(); builder.Continuity(newEdge, face1, face2, GeomAbs_Shape.GeomAbs_C0); // Set results context.NeutralPlane = newPlane; context.Source = newShape; context.Face = newFace; UpdateModifiedSubshapes(context.Source, splitShape); return(true); }