protected override void SolveInstance(IGH_DataAccess DA) { // 1. Get Input Data Curve path=null; DA.GetData(0, ref path); Plane pathPlane=new Plane(); DA.GetData(1, ref pathPlane); Curve section=null; DA.GetData(2, ref section); Plane sectionPlane=new Plane(); DA.GetData(3, ref sectionPlane); // 2. Orientate section profile to path Point3d origin = path.PointAtStart; Vector3d xDir = pathPlane.Normal; Vector3d yDir = path.TangentAt(path.Domain.T0); yDir.Rotate(Rhino.RhinoMath.ToRadians(90.0), xDir); Plane targetPlane = new Plane(origin,xDir,yDir); section.Transform(Transform.PlaneToPlane(sectionPlane, targetPlane)); // 3. Generate Member SweepOneRail sweep = new SweepOneRail(); Brep[] beam = sweep.PerformSweep(path, section); DA.SetDataList(0, beam); }
public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc) { Rhino.DocObjects.ObjRef rail_ref; var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref); if (rc != Rhino.Commands.Result.Success) { return(rc); } var rail_crv = rail_ref.Curve(); if (rail_crv == null) { return(Rhino.Commands.Result.Failure); } var gx = new Rhino.Input.Custom.GetObject(); gx.SetCommandPrompt("Select cross section curves"); gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gx.EnablePreSelect(false, true); gx.GetMultiple(1, 0); if (gx.CommandResult() != Rhino.Commands.Result.Success) { return(gx.CommandResult()); } var cross_sections = new List <Rhino.Geometry.Curve>(); for (int i = 0; i < gx.ObjectCount; i++) { var crv = gx.Object(i).Curve(); if (crv != null) { cross_sections.Add(crv); } } if (cross_sections.Count < 1) { return(Rhino.Commands.Result.Failure); } var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = doc.ModelAbsoluteTolerance; sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(rail_crv, cross_sections); for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Curve iRail = null; Curve iProfile = null; double iX = 0.0; double iY = 0.0; if (!DA.GetData(0, ref iRail)) { return; } if (!DA.GetData(0, ref iProfile)) { return; } if (!DA.GetData(1, ref iX)) { return; } if (!DA.GetData(2, ref iY)) { return; } Plane pln = new Plane(); iRail.PerpendicularFrameAt(0.0, out pln); var rect = new Rectangle3d(pln, iX, iY); Plane Orig = new Plane(0, 0, 1, 0); var xform1 = Rhino.Geometry.Transform.PlaneToPlane(Orig, pln); var rectC = rect.ToNurbsCurve(); if (iProfile != null) { iProfile.Transform(xform1); rectC = iProfile.ToNurbsCurve(); } var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = 0.017453; sweep.ClosedSweep = false; sweep.SweepTolerance = 0.001; sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(iRail, rectC); DA.SetDataList(0, breps); }
public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc) { Rhino.DocObjects.ObjRef rail_ref; var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref); if(rc!=Rhino.Commands.Result.Success) return rc; var rail_crv = rail_ref.Curve(); if( rail_crv==null ) return Rhino.Commands.Result.Failure; var gx = new Rhino.Input.Custom.GetObject(); gx.SetCommandPrompt("Select cross section curves"); gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gx.EnablePreSelect(false, true); gx.GetMultiple(1,0); if( gx.CommandResult() != Rhino.Commands.Result.Success ) return gx.CommandResult(); var cross_sections = new List<Rhino.Geometry.Curve>(); for( int i=0; i<gx.ObjectCount; i++ ) { var crv = gx.Object(i).Curve(); if( crv!= null) cross_sections.Add(crv); } if( cross_sections.Count<1 ) return Rhino.Commands.Result.Failure; var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = doc.ModelAbsoluteTolerance; sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(rail_crv, cross_sections); for( int i=0; i<breps.Length; i++ ) doc.Objects.AddBrep(breps[i]); doc.Views.Redraw(); return Rhino.Commands.Result.Success; }
// <Custom additional code> //Calculation of 45° roof with differents valley //Type = 0 => Round : Constant slope (sand) //Type = 1 => Butt : Angular (roof) //Type = 2 => Square : Simple public List <Brep> SandDune(Polyline polyline, int type, bool isV6, bool parallel) { List <Brep> output = new List <Brep>(); //By default round type if (type < 0) { type = 0; } if (type > 2) { type = 0; } if (polyline != null) { double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; bool isClosed = polyline.IsClosedWithinTolerance(tol); //Polyline is closed if not closed if (!isClosed) { polyline.Add(polyline[0]); } //Just in case polyline.CollapseShortSegments(tol * 2); Curve polylineCurve = polyline.ToNurbsCurve(); //Definition of orientation of polyline int orientation = 1; if (isV6) { //CurveOrientation (inverted in RH5 vs RH6 // Undefined 0 Orientation is undefined. // Clockwise -1 The curve's orientation is clockwise in the xy plane. // CounterClockwise 1 The curve's orientation is counter clockwise in the xy plane CurveOrientation curveOrientation = polylineCurve.ClosedCurveOrientation(Plane.WorldXY); if (curveOrientation == CurveOrientation.Clockwise) { orientation = -1; } else { orientation = 1; } } else { //Use of classical surface calculation of polyline if (SurfaceOnXYplane(polyline) > 0) { orientation = -1; } else { orientation = 1; } } //Bounding box calculation in order to have the max horizontal distances for the roofs surfaces (before cut) BoundingBox bb = polylineCurve.GetBoundingBox(false); double maxLength = bb.Diagonal.Length; //List of brep representing the roof before cut List <Brep> breps = new List <Brep>(); //Side of roof for (int i = 0; i < (polyline.Count - 1); i++) { //Calculate direction of line Point3d p1 = polyline[i]; Point3d p2 = polyline[(i + 1)]; Vector3d direction12 = (p2 - p1) * orientation; direction12.Unitize(); //Calculate a perpendicular Vector3d perp12 = Vector3d.CrossProduct(direction12, Vector3d.ZAxis); perp12.Unitize(); //Because move is one unit horizontal (per12) + one unit in Z => 45° //if you want other angle put a coefficient on perp12 (0 => 90°) Vector3d move = perp12 + Vector3d.ZAxis; move *= maxLength; //Make a sweep var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = RhinoDoc.ActiveDoc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; Brep[] sideBreps = sweep.PerformSweep(new LineCurve(p1, p1 + move), new LineCurve(p1, p2)); if (sideBreps.Length > 0) { breps.Add(sideBreps[0]); } } //Valley parts of the roof for (int i = 0; i < (polyline.Count - 1); i++) { //Calculate direction of line int index; if (i == 0) { index = polyline.Count - 2; } else { index = i - 1; } Point3d p1 = polyline[index]; Point3d p2 = polyline[i]; Point3d p3 = polyline[i + 1]; Vector3d direction12 = (p2 - p1); direction12.Unitize(); Vector3d direction23 = (p3 - p2); direction23.Unitize(); Brep rp = new Brep(); //Round type if (type == 0) { rp = ValleyRound(p2, direction12, direction23, maxLength, orientation); if (rp.IsValid) { breps.Add(rp); } } //Butt type if (type == 1) { Brep[] vv = ValleyButt(p2, direction12, direction23, maxLength, orientation); if (vv.Length >= 2) { if (vv[0].IsValid) { breps.Add(vv[0]); } if (vv[1].IsValid) { breps.Add(vv[1]); } } } //Square type if (type == 2) { rp = ValleySquare(p2, direction12, direction23, maxLength, orientation); if (rp.IsValid) { breps.Add(rp); } } } output = CutBreps(breps, tol, polylineCurve, parallel); } return(output); }
/***************************************************/ public static Rhino.Geometry.Surface ToRhino(this BHG.Extrusion extrusion) { if (!extrusion.Curve.IIsPlanar()) { BH.Engine.Reflection.Compute.RecordError("The provided BHoM Extrusion has a base curve that is not planar."); return(null); } var planarCurve = extrusion.Curve.IToRhino(); RHG.Plane curvePlane; planarCurve.TryGetPlane(out curvePlane); double angle = RHG.Vector3d.VectorAngle(curvePlane.Normal, extrusion.Direction.ToRhino()); double tolerance = 0.001; if (angle < tolerance || (2 * Math.PI - tolerance < angle && angle < 2 * Math.PI + tolerance)) { // It can be represented by a Rhino extrusion (which enforces perpendicularity btw Curve plane and Vector) double extrHeight = extrusion.Direction.Length(); if (angle > Math.PI) { extrHeight = -extrHeight; } RHG.Extrusion extr = Rhino.Geometry.Extrusion.Create(planarCurve, extrHeight, extrusion.Capped); return(extr); } // Otherwise, provide a Sweep to cover extrusion with a base curve that is not orthogonal to the extr direction // Create a Line to be the sweep rail. Use centroid/mid-point of base curve as start point. RHG.Point3d centrePoint; if (planarCurve.IsClosed) { var areaProp = Rhino.Geometry.AreaMassProperties.Compute(planarCurve); centrePoint = areaProp.Centroid; } else { centrePoint = planarCurve.PointAt(0.5); } RHG.Point3d endPoint = centrePoint + extrusion.Direction.ToRhino(); var rail = new RHG.LineCurve(centrePoint, endPoint); var joinedSweep = new RHG.SweepOneRail() .PerformSweep(rail, planarCurve) .Aggregate((b1, b2) => { b1.Join(b2, tolerance, true); return(b1); }); if (joinedSweep.IsSurface) { return(joinedSweep.Surfaces[0]); } BH.Engine.Reflection.Compute.RecordError("Could not convert this BHoM Extrusion to a Rhino Surface. The extrusion direction is not perpendicular to the base curve, and the base curve is too complex for a Sweep to return a valid Surface."); return(null); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //select the cross-section faces var gb = new Rhino.Input.Custom.GetObject(); gb.SetCommandPrompt("Select the surfaces which form the cross-section of the beam."); gb.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gb.EnablePreSelect(false, true); gb.GetMultiple(1, 0); if (gb.CommandResult() != Rhino.Commands.Result.Success) { return(gb.CommandResult()); } List <BrepFace> cross_section = new List <BrepFace>(); for (int i = 0; i < gb.ObjectCount; i++) { var face = gb.Object(i).Face(); if (face != null) { cross_section.Add(face); } } //select the rail Rhino.DocObjects.ObjRef rail_ref; var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref); if (rc != Rhino.Commands.Result.Success) { return(rc); } var rail_crv = rail_ref.Curve(); if (rail_crv == null) { return(Rhino.Commands.Result.Failure); } var gx = new Rhino.Input.Custom.GetObject(); gx.SetCommandPrompt("Select cross section curves"); gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gx.EnablePreSelect(false, true); gx.GetMultiple(1, 0); if (gx.CommandResult() != Rhino.Commands.Result.Success) { return(gx.CommandResult()); } var cross_sections = new List <Rhino.Geometry.Curve>(); for (int i = 0; i < gx.ObjectCount; i++) { var crv = gx.Object(i).Curve(); if (crv != null) { cross_sections.Add(crv); } } if (cross_sections.Count < 1) { return(Rhino.Commands.Result.Failure); } var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = doc.ModelAbsoluteTolerance; //sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(rail_crv, cross_sections); for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }