/// <summary> /// Convert a Nucleus Linear Element to a Rhino Extrusion, if possible /// </summary> /// <param name="element"></param> /// <returns></returns> public static RC.Extrusion ConvertToExtrusion(LinearElement element) { Curve perimeter = element?.Family?.Profile?.Perimeter; CurveCollection voids = element?.Family?.Profile?.Voids; if (perimeter != null && element.Geometry != null) { RC.Curve profile = Convert(perimeter); var cSystem = element.Geometry.LocalCoordinateSystem(0, element.Orientation); if (element.Geometry is Line) { //If a line, create an extrusion: RC.Extrusion ext = new RC.Extrusion(); ext.SetPathAndUp( Convert(element.Geometry.EndPoint), Convert(element.Geometry.StartPoint), ConvertVector(cSystem.Z)); ext.SetOuterProfile(profile, true); if (voids != null) { var voidCrvs = Convert(voids); foreach (var rCrv in voidCrvs) { ext.AddInnerProfile(rCrv); } } //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position))); return(ext); } } return(null); }
/// <summary> /// Convert a Nucleus extrusion volume to a Rhino one /// </summary> /// <param name="extrusion"></param> /// <returns></returns> public static RC.Extrusion Convert(Extrusion extrusion) { if (extrusion.IsValid) { Curve perimeter = extrusion.Profile?.Perimeter; CurveCollection voids = extrusion.Profile?.Voids; if (perimeter != null) { RC.Curve profile = Convert(perimeter); // var cSystem = new CartesianCoordinateSystem(new Vector(), extrusion.Path); //If a line, create an extrusion: RC.Extrusion ext = new RC.Extrusion(); ext.SetPathAndUp(new RC.Point3d(0, 0, 0), Convert(extrusion.Path), RC.Vector3d.YAxis); //TODO: Test! //ConvertVector(cSystem.Z)); ext.SetOuterProfile(profile, true); if (voids != null) { var voidCrvs = Convert(voids); foreach (var rCrv in voidCrvs) { ext.AddInnerProfile(rCrv); } } //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position))); return(ext); } } return(null); }
/// <summary> /// Replace an extrusion object in the current Rhino document /// </summary> /// <param name="objID"></param> /// <param name="extrusion"></param> /// <returns></returns> public static bool ReplaceExtrusion(Guid objID, RC.Extrusion extrusion) { bool result = false; Writing = true; result = RhinoDoc.ActiveDoc.Objects.Replace(objID, extrusion); Writing = false; return(result); }
// Extrusions public static SpeckleExtrusion ToSpeckle(this Rhino.Geometry.Extrusion extrusion) { //extrusion.PathTangent var myExtrusion = new SpeckleExtrusion(extrusion.Profile3d(0, 0).ToSpeckle(), extrusion.PathStart.DistanceTo(extrusion.PathEnd), extrusion.IsCappedAtBottom); myExtrusion.PathTangent = extrusion.PathTangent.ToSpeckle(); myExtrusion.PathStart = extrusion.PathStart.ToSpeckle(); myExtrusion.PathEnd = extrusion.PathEnd.ToSpeckle(); myExtrusion.Properties = extrusion.UserDictionary.ToSpeckle(); myExtrusion.SetHashes(myExtrusion); return(myExtrusion); }
// Extrusions // TODO: Research into how to properly create and recreate extrusions. Current way we compromise by transforming them into breps. public static SpeckleBrep ToSpeckle(this Rhino.Geometry.Extrusion extrusion) { return(extrusion.ToBrep().ToSpeckle()); //var myExtrusion = new SpeckleExtrusion( SpeckleCore.Converter.Serialise( extrusion.Profile3d( 0, 0 ) ), extrusion.PathStart.DistanceTo( extrusion.PathEnd ), extrusion.IsCappedAtBottom ); //myExtrusion.PathStart = extrusion.PathStart.ToSpeckle(); //myExtrusion.PathEnd = extrusion.PathEnd.ToSpeckle(); //myExtrusion.PathTangent = extrusion.PathTangent.ToSpeckle(); //var Profiles = new List<SpeckleObject>(); //for ( int i = 0; i < extrusion.ProfileCount; i++ ) // Profiles.Add( SpeckleCore.Converter.Serialise( extrusion.Profile3d( i, 0 ) ) ); //myExtrusion.Profiles = Profiles; //myExtrusion.Properties = extrusion.UserDictionary.ToSpeckle( root: extrusion ); //myExtrusion.GenerateHash(); //return myExtrusion; }
public static global::Topologic.Face ToTopologic(this Rhino.Geometry.Surface surface) { if (surface == null) { return(null); } SumSurface sumSurface = surface as SumSurface; if (sumSurface != null) { return(sumSurface.ToTopologic()); } RevSurface revSurface = surface as RevSurface; if (revSurface != null) { return(revSurface.ToTopologic()); } PlaneSurface planeSurface = surface as PlaneSurface; if (planeSurface != null) { return(planeSurface.ToTopologic()); } Rhino.Geometry.Extrusion ghExtrusion = surface as Rhino.Geometry.Extrusion; if (ghExtrusion != null) { return(ghExtrusion.ToTopologic()); } Rhino.Geometry.NurbsSurface ghNurbsSurface = surface as Rhino.Geometry.NurbsSurface; if (ghNurbsSurface != null) { return(ghNurbsSurface.ToTopologic()); } return(null); }
// Extrusions public static SpeckleExtrusion ToSpeckle(this Rhino.Geometry.Extrusion extrusion) { //extrusion.PathTangent var myExtrusion = new SpeckleExtrusion(extrusion.Profile3d(0, 0).ToSpeckle(), extrusion.PathStart.DistanceTo(extrusion.PathEnd), extrusion.IsCappedAtBottom); myExtrusion.PathStart = extrusion.PathStart.ToSpeckle(); myExtrusion.PathEnd = extrusion.PathEnd.ToSpeckle(); myExtrusion.PathTangent = extrusion.PathTangent.ToSpeckle(); myExtrusion.ProfileTransformation = extrusion.GetProfileTransformation(0.0); var Profiles = new List <SpeckleObject>(); for (int i = 0; i < extrusion.ProfileCount; i++) { Profiles.Add(extrusion.Profile3d(i, 0).ToSpeckle()); } myExtrusion.Profiles = Profiles; myExtrusion.Properties = extrusion.UserDictionary.ToSpeckle(); myExtrusion.SetHashes(myExtrusion); return(myExtrusion); }
/***************************************************/ public static BHG.IGeometry FromRhino(this RHG.Extrusion extrusion) { if (extrusion == null) { return(null); } RHG.LineCurve line = extrusion.PathLineCurve(); BHG.Vector extrVec = BH.Engine.Geometry.Create.Vector(line.PointAtStart.FromRhino(), line.PointAtEnd.FromRhino()); List <BHG.Extrusion> extrs = new List <BHG.Extrusion>(); // Exploits the fact that GetWireframe returns first the "profile" curves of the extrusion. var profileCurves = extrusion.GetWireframe(); for (int i = 0; i < extrusion.ProfileCount; i++) { var profileConverted = profileCurves.ElementAt(i).FromRhino(); BHG.Extrusion extr = BH.Engine.Geometry.Create.Extrusion(profileConverted, extrVec, extrusion.IsCappedAtBottom && extrusion.IsCappedAtTop); extrs.Add(extr); } if (extrs.Count == 1) { return(extrs[0]); } if (extrs.Count > 1) { return new BH.oM.Geometry.CompositeGeometry() { Elements = extrs.OfType <BH.oM.Geometry.IGeometry>().ToList() } } ; BH.Engine.Reflection.Compute.RecordError("Could not convert the extrusion."); return(null); }
public RV.DirectShape ExtrusionToDirectShape(RH.Extrusion extrusion, string[] args) { if (args.Length == 0) { return(null); } if (!Enum.TryParse($"{args[0]}s", out RV.RevitCategory category)) { return(null); } string name = "DirectShape"; try { name = args[1]; } catch { } return(new RV.DirectShape(name, category, new List <Base>() { ConvertToSpeckle(extrusion) }) { units = ModelUnits }); }
public static global::Topologic.Face ToTopologic(Rhino.Geometry.Extrusion extrusion) { Rhino.Geometry.NurbsSurface ghNurbsSurface = extrusion?.ToNurbsSurface(); return(ghNurbsSurface?.ToTopologic()); }
/***************************************************/ /**** Public Methods - Surfaces ****/ /***************************************************/ public static void RenderRhinoWires(RHG.Extrusion surface, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness) { pipeline.DrawSurface(surface, bhColour, thickness); }
public SurfaceConverter(CurveConverter curveConv, Vector3DConverter vecConv, Point3dConverter ptConv) { //extrusion surfaces AddConverter(new PipeConverter <rh.Extrusion, pps.Extrusion>( (rhE) => { ppc.Line path = (ppc.Line)curveConv.ConvertToPipe <rh.Curve, ppc.Curve>(rhE.PathLineCurve()); pps.Extrusion extr = new pps.Extrusion(curveConv.ConvertToPipe <rh.Curve, ppc.Curve>(rhE.Profile3d(0, 0)), vecConv.ConvertToPipe <rh.Vector3d, pp.Vec>(rhE.PathTangent), path.Length); for (int i = 1; i < rhE.ProfileCount; i++) { extr.Holes.Add(curveConv.ConvertToPipe <rh.Curve, ppc.Curve>(rhE.Profile3d(i, 0))); } extr.CappedAtStart = rhE.IsCappedAtBottom; extr.CappedAtEnd = rhE.IsCappedAtTop; extr.SurfaceNormal = vecConv.ToPipe <rh.Vector3d, pp.Vec>(rhE.NormalAt(rhE.Domain(0).Mid, rhE.Domain(1).Mid)); return(extr); }, (ppE) => { if (1 - ppE.Direction.Dot(new pp.Vec(0, 0, 1)) > 1e-3) { //the extrusion is not vertical throw new InvalidOperationException("Cannot create this extrusion. " + "Try converting it into a polysurface and pushing it again"); } var profile = curveConv.FromPipe <rh.Curve, ppc.Curve>(ppE.ProfileCurve); rh.Extrusion extr = rh.Extrusion.Create(profile, ppE.Height, ppE.CappedAtEnd || ppE.CappedAtStart); ppE.Holes.ForEach((h) => extr.AddInnerProfile(curveConv.FromPipe <rh.Curve, ppc.Curve>(h))); //extr.SetOuterProfile(profile, false); //extr.SetPathAndUp(profile.PointAtStart, profile.PointAtStart + pathVec, pathVec); string msg; if (!extr.IsValidWithLog(out msg)) { System.Diagnostics.Debug.WriteLine(msg); throw new InvalidOperationException("Cannot create a valid extrusion from the received data: \n" + msg); } var rhNorm = extr.NormalAt(extr.Domain(0).Mid, extr.Domain(1).Mid); if (rh.Vector3d.Multiply(rhNorm, vecConv.FromPipe <rh.Vector3d, pp.Vec>(ppE.SurfaceNormal)) < 0) { //extrusions don't need to be flipped; } return(extr); } )); //NurbsSurfaces AddConverter(new PipeConverter <rh.NurbsSurface, pps.NurbsSurface>( (rns) => { pps.NurbsSurface nurbs = new pps.NurbsSurface(rns.Points.CountU, rns.Points.CountV, rns.Degree(0), rns.Degree(1)); for (int u = 0; u < rns.Points.CountU; u++) { for (int v = 0; v < rns.Points.CountV; v++) { nurbs.SetControlPoint(ptConv.ToPipe <rh.Point3d, pp.Vec>(rns.Points.GetControlPoint(u, v).Location), u, v); nurbs.SetWeight(rns.Points.GetControlPoint(u, v).Weight, u, v); } } rh.Interval uDomain = rns.Domain(0); rh.Interval vDomain = rns.Domain(1); Func <double, rh.Interval, double> scaleKnot = (k, domain) => (k - domain.Min) / (domain.Length); nurbs.UKnots = rns.KnotsU.Select((k) => scaleKnot.Invoke(k, uDomain)).ToList(); nurbs.VKnots = rns.KnotsV.Select((k) => scaleKnot.Invoke(k, vDomain)).ToList(); nurbs.IsClosedInU = rns.IsClosed(0); nurbs.IsClosedInV = rns.IsClosed(1); nurbs.SurfaceNormal = vecConv.ToPipe <rh.Vector3d, pp.Vec>(rns.NormalAt(rns.Domain(0).Mid, rns.Domain(1).Mid)); return(nurbs); }, (pns) => { if (pns.IsClosedInU) { pns.WrapPointsToCloseSurface(0); } if (pns.IsClosedInV) { pns.WrapPointsToCloseSurface(1); } var nurbs = rh.NurbsSurface.Create(3, true, pns.UDegree + 1, pns.VDegree + 1, pns.UCount, pns.VCount); for (int u = 0; u < pns.UCount; u++) { for (int v = 0; v < pns.VCount; v++) { var cp = new rh.ControlPoint(ptConv.FromPipe <rh.Point3d, pp.Vec>(pns.GetControlPointAt(u, v)), pns.GetWeightAt(u, v)); nurbs.Points.SetControlPoint(u, v, cp); } } rh.Interval uDomain = nurbs.Domain(0); rh.Interval vDomain = nurbs.Domain(1); Func <double, rh.Interval, double> scaleKnot = (k, domain) => k * (domain.Length) + domain.Min; if (nurbs.KnotsU.Count == pns.UKnots.Count) { for (int i = 0; i < nurbs.KnotsU.Count; i++) { nurbs.KnotsU[i] = scaleKnot.Invoke(pns.UKnots[i], uDomain); } } if (nurbs.KnotsV.Count == pns.VKnots.Count) { for (int i = 0; i < nurbs.KnotsV.Count; i++) { nurbs.KnotsV[i] = scaleKnot.Invoke(pns.VKnots[i], vDomain); } } string msg; if (!nurbs.IsValidWithLog(out msg)) { System.Diagnostics.Debug.WriteLine(msg); if (!nurbs.IsPeriodic(0)) { nurbs.KnotsU.CreateUniformKnots(1.0 / (nurbs.Points.CountU)); } else { nurbs.KnotsU.CreatePeriodicKnots(1.0 / (nurbs.Points.CountU)); } if (!nurbs.IsPeriodic(1)) { nurbs.KnotsV.CreateUniformKnots(1.0 / (nurbs.Points.CountV)); } else { nurbs.KnotsV.CreatePeriodicKnots(1.0 / (nurbs.Points.CountV)); } if (!nurbs.IsValid) { throw new InvalidOperationException("Cannot create a valid NURBS surface: \n" + msg); } } var rhNorm = nurbs.NormalAt(nurbs.Domain(0).Mid, nurbs.Domain(1).Mid); if (rh.Vector3d.Multiply(rhNorm, vecConv.FromPipe <rh.Vector3d, pp.Vec>(pns.SurfaceNormal)) < 0) { //need not flip rhino surfaces } return(nurbs); } )); }
/// <summary> /// Add a new extrusion object to the current Rhino document /// </summary> /// <param name="extrusion"></param> /// <returns></returns> public static Guid BakeExtrusion(RC.Extrusion extrusion) { return(RhinoDoc.ActiveDoc.Objects.AddExtrusion(extrusion)); }
protected override void DrawOverlay(Rhino.Display.DrawEventArgs e) { base.DrawOverlay(e); List <Guid> noDupGUIDs = new List <Guid>(); for (int i = 0; i < Ids.Count; i++) { if (noDupGUIDs.Contains(Ids[i])) { } else { noDupGUIDs.Add(Ids[i]); RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(Ids[i]); int isSelected = foundObject.IsSelected(false); switch (foundObject.ObjectType) { case Rhino.DocObjects.ObjectType.Point: if (isSelected > 0) { e.Display.DrawDot(((Rhino.Geometry.Point)foundObject.Geometry).Location, i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } else { e.Display.DrawDot(((Rhino.Geometry.Point)foundObject.Geometry).Location, i.ToString(), System.Drawing.Color.Black, System.Drawing.Color.White); } break; case Rhino.DocObjects.ObjectType.Curve: Rhino.Geometry.Curve myCurve = (Rhino.Geometry.Curve)foundObject.Geometry; myCurve.Domain = new Rhino.Geometry.Interval(0, 1); if (isSelected > 0) { e.Display.DrawDot(myCurve.PointAtNormalizedLength(0.5), i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } else { e.Display.DrawDot(myCurve.PointAtNormalizedLength(0.5), i.ToString(), System.Drawing.Color.Black, System.Drawing.Color.White); } break; case Rhino.DocObjects.ObjectType.Extrusion: Rhino.Geometry.Extrusion myExtru = (Rhino.Geometry.Extrusion)foundObject.Geometry; Rhino.Geometry.Point3d myExtruLocation = myExtru.GetBoundingBox(true).Center; //Rhino.Geometry.Point3d myExtruCentroid = Rhino.Geometry.AreaMassProperties.Compute(myExtru.ToBrep()).Centroid; if (isSelected > 0) { e.Display.DrawDot(myExtruLocation, i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } else { e.Display.DrawDot(myExtruLocation, i.ToString(), System.Drawing.Color.Black, System.Drawing.Color.White); } break; case Rhino.DocObjects.ObjectType.Brep: Rhino.Geometry.Brep myBrep = (Rhino.Geometry.Brep)foundObject.Geometry; Rhino.Geometry.Point3d myBrepLocation = myBrep.GetBoundingBox(true).Center; if (isSelected > 0) { e.Display.DrawDot(myBrepLocation, i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } else { e.Display.DrawDot(myBrepLocation, i.ToString(), System.Drawing.Color.Black, System.Drawing.Color.White); } break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = foundObject.Geometry as Rhino.Geometry.Mesh; Rhino.Geometry.Point3d myMeshLocation = mesh.GetBoundingBox(true).Center; if (isSelected > 0) { e.Display.DrawDot(myMeshLocation, i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } else { e.Display.DrawDot(myMeshLocation, i.ToString(), System.Drawing.Color.Black, System.Drawing.Color.White); } break; case Rhino.DocObjects.ObjectType.TextDot: var textDot = (TextDot)foundObject.Geometry; break; case Rhino.DocObjects.ObjectType.Annotation: var textObj = (Rhino.Geometry.TextEntity)foundObject.Geometry; break; } } } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
/***************************************************/ /**** Public Methods - Surfaces ****/ /***************************************************/ public static RHG.Mesh CreatePreviewMesh(RHG.Extrusion surface, RHG.MeshingParameters parameters) { return(CreatePreviewMesh(surface.ToBrep(), parameters)); }
public static bool TryGetExtrusion(this Surface surface, out Extrusion extrusion) { extrusion = null; var nurbsSurface = surface as NurbsSurface ?? surface.ToNurbsSurface(); for (int direction = 1; direction >= 0; --direction) { var oposite = direction == 0 ? 1 : 0; if (surface.IsClosed(direction)) { continue; } var domain = nurbsSurface.Domain(direction); var iso0 = nurbsSurface.IsoCurve(oposite, domain.Min); var iso1 = nurbsSurface.IsoCurve(oposite, domain.Max); if (iso0.TryGetPlane(out var plane0) && iso1.TryGetPlane(out var plane1)) { if (plane0.Normal.IsParallelTo(plane1.Normal, RhinoMath.DefaultAngleTolerance / 100.0) == 1) { var rowCount = direction == 0 ? nurbsSurface.Points.CountU : nurbsSurface.Points.CountV; var columnCount = direction == 0 ? nurbsSurface.Points.CountV : nurbsSurface.Points.CountU; for (int c = 0; c < columnCount; ++c) { var point = direction == 0 ? nurbsSurface.Points.GetControlPoint(0, c) : nurbsSurface.Points.GetControlPoint(c, 0); for (int r = 1; r < rowCount; ++r) { var pointR = direction == 0 ? nurbsSurface.Points.GetControlPoint(r, c) : nurbsSurface.Points.GetControlPoint(c, r); var projectedPointR = plane0.ClosestPoint(pointR.Location); if (projectedPointR.DistanceToSquared(point.Location) > RhinoMath.SqrtEpsilon) { return(false); } if (Math.Abs(pointR.Weight - point.Weight) > RhinoMath.ZeroTolerance) { return(false); } } } // Extrusion.Create does not work well when 'iso0' is a line-like curve, // plane used to extrude is "arbitrary" in this case //extrusion = Extrusion.Create(iso0, zAxis.Length, false); var axis = new Line(iso0.PointAtStart, iso1.PointAtStart); var zAxis = iso1.PointAtStart - iso0.PointAtStart; var xAxis = (iso0.IsClosed ? iso0.PointAt(iso0.Domain.Mid) : iso0.PointAtEnd) - iso0.PointAtStart; var yAxis = Vector3d.CrossProduct(zAxis, xAxis); extrusion = new Extrusion(); if (!iso0.Transform(Transform.PlaneToPlane(new Plane(iso0.PointAtStart, xAxis, yAxis), Plane.WorldXY))) { return(false); } return(extrusion.SetPathAndUp(axis.From, axis.To, yAxis) && extrusion.SetOuterProfile(iso0, false)); } } } return(false); }
public static bool TryGetExtrusion(this Brep brep, out Extrusion extrusion) { if (brep.IsSurface) { return(brep.Faces[0].TryGetExtrusion(out extrusion)); } extrusion = null; if (brep.Faces.Count < 3) { return(false); } // Requiere manifold breps if (brep.SolidOrientation == BrepSolidOrientation.None || brep.SolidOrientation == BrepSolidOrientation.Unknown) { return(false); } // If brep has more that 3 faces we should check if there are faces with interior loops if (brep.Faces.Count > 3 && brep.Faces.Where(face => face.Loops.Count != 1).Any()) { return(false); } var candidateFaces = new List <int[]>(); // Array with just planar faces sorted by its area to search for similar faces var planarFaces = brep.Faces. Select(face => new PlanarBrepFace(face)). Where(face => face.Plane.IsValid). OrderByDescending(face => face.LoopArea). ToArray(); // A capped Extrusion converted to Brep has wall surfaces in face[0] to face[N-3], caps are face[N-2] and face[N-1] // I iterate in reverse order to be optimisitc, maybe brep comes from an Extrusion.ToBrep() call for (int f = planarFaces.Length - 1; f > 0; --f) { var planeF = planarFaces[f].Plane; var loopF = planarFaces[f].Loop; var centroidF = planarFaces[f].Centroid; // Check if they have same area. for (int g = f - 1; g >= 0 && RhinoMath.EpsilonEquals(planarFaces[f].LoopArea, planarFaces[g].LoopArea, RhinoMath.SqrtEpsilon); --g) { // Planes should be parallel or anti-parallel if (planeF.Normal.IsParallelTo(planarFaces[g].Plane.Normal, RhinoMath.DefaultAngleTolerance / 100.0) == 0) { continue; } // Here f, and g are perfect candidates to test adjacent faces for perpendicularity to them, // but we may try to quick reject some candidates if it's obvious that doesn't match // A "perfect" curve overlap match may be a test but is too much in this ocasion // We expect same NURBS structure, so point count should match if (loopF.Points.Count != planarFaces[g].Loop.Points.Count) { continue; } // Since we have computed the area the centroid comes for free. // Centroids should also match if (planeF.ClosestPoint(planarFaces[g].Centroid).DistanceToSquared(centroidF) > RhinoMath.SqrtEpsilon) { continue; } // Add result to candidates List reversing index order to keep extrusion creation direction // Breps that come from a Extrusion have the Cap[0] before Cap[1] candidateFaces.Add(new int[] { g, f }); } } // No twin faces found if (candidateFaces.Count == 0) { return(false); } // Candidates are in 'LoopArea' order, we will find here smaller profiles sooner // This is good for beam like objects, bad for slab like objects. // On box-like Breps the result could be ambigous for the user so, // to give him some control on the result, we will prioritize first and last faces no matter their area. // First and Last are "special" because if somebody observe an extrusion-like Brep and sees // it as an extrusion he tends to categorize faces in one of the following schemas: // { Cap[0], Wall[0] .. Wall[N], Cap[1] } // { Cap[0], Cap[1], Wall[0] .. Wall[N] } // { Wall[0] .. Wall[N], Cap[0], Cap[1] } // So if he is using the join command to create a Brep from surfaces at the model, // it's natural to start or end the selection with one of the extrusion caps. // On horizontal extrusions, slab-like Breps, the user use to observe the model from above, // so probably he will end with the bottom cap. // Also Last face is a Cap in Breps that come from Extrusion // If caps and walls are interleaved, smallest pair of faces will be used as caps, producing beam-like extrusions. // System.Linq.Enumerable.OrderBy performs a stable sort so only first and last face will be moved if found. foreach (var candidate in candidateFaces.OrderBy(pair => (planarFaces[pair[1]].Face.FaceIndex == brep.Faces.Count - 1) ? 0 : // Last, in case it comes from Extrusion (planarFaces[pair[0]].Face.FaceIndex == 0) ? 1 : // First, in case it comes from a JOIN command int.MaxValue)) // Others { var startFace = planarFaces[candidate[0]]; var endFace = planarFaces[candidate[1]]; // If any face, ignorig twins candidates, does not degenrate // to a curve when projected to 'planeF', then brep is not an extrusion if ( brep.Faces. Where(face => face.FaceIndex != startFace.Face.FaceIndex && face.FaceIndex != endFace.Face.FaceIndex). Select(face => startFace.ProjectionDegenartesToCurve(face.UnderlyingSurface())). Any(degenerateToCurve => degenerateToCurve == false) ) { return(false); } // We use the orginal OuterLoop as profile not the NURBS version of it // to keep the structure as much as possible var profile = startFace.Face.OuterLoop.To3dCurve(); double height = startFace.Face.OrientationIsReversed ? -startFace.Plane.DistanceTo(endFace.Plane.Origin) : +startFace.Plane.DistanceTo(endFace.Plane.Origin); extrusion = Extrusion.Create(profile, height, true); return(extrusion is object); } return(false); }
public Extrusion ToExtrusion() { return(Extrusion.CreateBoxExtrusion(this, true)); }
/***************************************************/ /**** Public Methods - Surfaces ****/ /***************************************************/ public static void RenderRhinoMeshes(RHG.Extrusion surface, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { pipeline.DrawBrepShaded(surface.ToBrep(), material); }
internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobject_index) { if (IntPtr.Zero == pGeometry) return null; int type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry); if (type < 0) return null; GeometryBase rc = null; switch (type) { case idxON_Curve: //1 rc = new Curve(pGeometry, parent, subobject_index); break; case idxON_NurbsCurve: //2 rc = new NurbsCurve(pGeometry, parent, subobject_index); break; case idxON_PolyCurve: // 3 rc = new PolyCurve(pGeometry, parent, subobject_index); break; case idxON_PolylineCurve: //4 rc = new PolylineCurve(pGeometry, parent, subobject_index); break; case idxON_ArcCurve: //5 rc = new ArcCurve(pGeometry, parent, subobject_index); break; case idxON_LineCurve: //6 rc = new LineCurve(pGeometry, parent, subobject_index); break; case idxON_Mesh: //7 rc = new Mesh(pGeometry, parent); break; case idxON_Point: //8 rc = new Point(pGeometry, parent); break; case idxON_TextDot: //9 rc = new TextDot(pGeometry, parent); break; case idxON_Surface: //10 rc = new Surface(pGeometry, parent); break; case idxON_Brep: //11 rc = new Brep(pGeometry, parent); break; case idxON_NurbsSurface: //12 rc = new NurbsSurface(pGeometry, parent); break; case idxON_RevSurface: //13 rc = new RevSurface(pGeometry, parent); break; case idxON_PlaneSurface: //14 rc = new PlaneSurface(pGeometry, parent); break; case idxON_ClippingPlaneSurface: //15 rc = new ClippingPlaneSurface(pGeometry, parent); break; case idxON_Annotation2: // 16 rc = new AnnotationBase(pGeometry, parent); break; case idxON_Hatch: // 17 rc = new Hatch(pGeometry, parent); break; case idxON_TextEntity2: //18 rc = new TextEntity(pGeometry, parent); break; case idxON_SumSurface: //19 rc = new SumSurface(pGeometry, parent); break; case idxON_BrepFace: //20 { int faceindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex); if (pBrep != IntPtr.Zero && faceindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Faces[faceindex]; } } break; case idxON_BrepEdge: // 21 { int edgeindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex); if (pBrep != IntPtr.Zero && edgeindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Edges[edgeindex]; } } break; case idxON_InstanceDefinition: // 22 rc = new InstanceDefinitionGeometry(pGeometry, parent); break; case idxON_InstanceReference: // 23 rc = new InstanceReferenceGeometry(pGeometry, parent); break; #if USING_V5_SDK case idxON_Extrusion: //24 rc = new Extrusion(pGeometry, parent); break; #endif case idxON_LinearDimension2: //25 rc = new LinearDimension(pGeometry, parent); break; case idxON_PointCloud: // 26 rc = new PointCloud(pGeometry, parent); break; case idxON_DetailView: // 27 rc = new DetailView(pGeometry, parent); break; case idxON_AngularDimension2: // 28 rc = new AngularDimension(pGeometry, parent); break; case idxON_RadialDimension2: // 29 rc = new RadialDimension(pGeometry, parent); break; case idxON_Leader: // 30 rc = new Leader(pGeometry, parent); break; case idxON_OrdinateDimension2: // 31 rc = new OrdinateDimension(pGeometry, parent); break; case idxON_Light: //32 rc = new Light(pGeometry, parent); break; case idxON_PointGrid: //33 rc = new Point3dGrid(pGeometry, parent); break; case idxON_MorphControl: //34 rc = new MorphControl(pGeometry, parent); break; case idxON_BrepLoop: //35 { int loopindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex); if (pBrep != IntPtr.Zero && loopindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Loops[loopindex]; } } break; case idxON_BrepTrim: // 36 { int trimindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex); if (pBrep != IntPtr.Zero && trimindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Trims[trimindex]; } } break; default: rc = new UnknownGeometry(pGeometry, parent, subobject_index); break; } return rc; }
public bool SetFromExtrusion(Extrusion extrusion) { IntPtr pThis = NonConstPointer(); IntPtr pConstExtrusion = extrusion.ConstPointer(); return UnsafeNativeMethods.CRhinoGumball_SetFromExtrusion(pThis, pConstExtrusion); }
protected override void DrawForeground(DrawEventArgs e) { base.DrawForeground(e); RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(Id); Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport; e.Display.EnableDepthWriting(false); switch (foundObject.ObjectType) { case Rhino.DocObjects.ObjectType.Point: break; case Rhino.DocObjects.ObjectType.Curve: break; case Rhino.DocObjects.ObjectType.Extrusion: Rhino.Geometry.Extrusion myExtru = (Rhino.Geometry.Extrusion)foundObject.Geometry; Rhino.Geometry.Brep myBrep = myExtru.ToBrep(); Mesh[] extruMeshes = Rhino.Geometry.Mesh.CreateFromBrep(myBrep); Mesh globalExtruMesh = new Rhino.Geometry.Mesh(); foreach (Mesh m in extruMeshes) { globalExtruMesh.Append(m); } Polyline[] myExtruPoly = globalExtruMesh.GetOutlines(viewport); foreach (Polyline poly in myExtruPoly) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.Brep: Mesh[] meshes = Rhino.Geometry.Mesh.CreateFromBrep((Brep)foundObject.Geometry); Mesh globalMesh = new Rhino.Geometry.Mesh(); foreach (Mesh m in meshes) { globalMesh.Append(m); } Polyline[] myPolys2 = globalMesh.GetOutlines(viewport); foreach (Polyline poly in myPolys2) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.Mesh: Mesh mesh = foundObject.Geometry as Rhino.Geometry.Mesh; Polyline[] meshOutline = mesh.GetOutlines(viewport); foreach (Polyline poly in meshOutline) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.TextDot: break; case Rhino.DocObjects.ObjectType.Annotation: break; } e.Display.EnableDepthWriting(true); e.Display.EnableDepthWriting(false); if (Edges.Count > 0) { System.Drawing.Color colorKid = System.Drawing.Color.LightCoral; foreach (List <Guid> li in Edges) { RhinoObject foundObject0 = Rhino.RhinoDoc.ActiveDoc.Objects.Find(li[0]); RhinoObject foundObject1 = Rhino.RhinoDoc.ActiveDoc.Objects.Find(li[1]); Rhino.Geometry.Point3d ce0 = new Rhino.Geometry.Point3d(); Rhino.Geometry.Point3d ce1 = new Rhino.Geometry.Point3d(); switch (foundObject0.ObjectType) { case Rhino.DocObjects.ObjectType.Point: ce0 = ((Rhino.Geometry.Point)foundObject0.Geometry).Location; break; case Rhino.DocObjects.ObjectType.Curve: Rhino.Geometry.Curve myCurve = (Rhino.Geometry.Curve)foundObject0.Geometry; myCurve.Domain = new Rhino.Geometry.Interval(0, 1); ce0 = myCurve.PointAtNormalizedLength(0.5); break; case Rhino.DocObjects.ObjectType.Extrusion: Rhino.Geometry.Extrusion myExtru = (Rhino.Geometry.Extrusion)foundObject0.Geometry; Rhino.Geometry.Point3d myExtruCentroid = Rhino.Geometry.AreaMassProperties.Compute(myExtru.ToBrep()).Centroid; ce0 = myExtruCentroid; Rhino.Geometry.Brep myBrep = myExtru.ToBrep(); Mesh[] extruMeshes = Rhino.Geometry.Mesh.CreateFromBrep(myBrep); Mesh globalExtruMesh = new Rhino.Geometry.Mesh(); foreach (Mesh m in extruMeshes) { globalExtruMesh.Append(m); } Polyline[] myExtruPoly = globalExtruMesh.GetOutlines(viewport); foreach (Polyline poly in myExtruPoly) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.Brep: Rhino.Geometry.Point3d myBrepCentroid = ((Brep)foundObject0.Geometry).GetBoundingBox(true).Center; ce0 = myBrepCentroid; Mesh[] meshes = Rhino.Geometry.Mesh.CreateFromBrep((Brep)foundObject0.Geometry); Mesh globalMesh = new Rhino.Geometry.Mesh(); foreach (Mesh m in meshes) { globalMesh.Append(m); } Polyline[] myPolys2 = globalMesh.GetOutlines(viewport); foreach (Polyline poly in myPolys2) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = foundObject0.Geometry as Rhino.Geometry.Mesh; Polyline[] meshOutline = mesh.GetOutlines(viewport); foreach (Polyline poly in meshOutline) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } Rhino.Geometry.Point3d myMeshCentroid = mesh.GetBoundingBox(true).Center; ce0 = myMeshCentroid; break; case Rhino.DocObjects.ObjectType.TextDot: // todo break; case Rhino.DocObjects.ObjectType.Annotation: // todo break; } switch (foundObject1.ObjectType) { case Rhino.DocObjects.ObjectType.Point: ce1 = ((Rhino.Geometry.Point)foundObject1.Geometry).Location; break; case Rhino.DocObjects.ObjectType.Curve: Rhino.Geometry.Curve myCurve = (Rhino.Geometry.Curve)foundObject1.Geometry; myCurve.Domain = new Rhino.Geometry.Interval(0, 1); ce1 = myCurve.PointAtNormalizedLength(0.5); break; case Rhino.DocObjects.ObjectType.Extrusion: Rhino.Geometry.Extrusion myExtru = (Rhino.Geometry.Extrusion)foundObject1.Geometry; Rhino.Geometry.Point3d myExtruCentroid = Rhino.Geometry.AreaMassProperties.Compute(myExtru.ToBrep()).Centroid; ce1 = myExtruCentroid; Rhino.Geometry.Brep myBrep = myExtru.ToBrep(); Mesh[] extruMeshes = Rhino.Geometry.Mesh.CreateFromBrep(myBrep); Mesh globalExtruMesh = new Rhino.Geometry.Mesh(); foreach (Mesh m in extruMeshes) { globalExtruMesh.Append(m); } Polyline[] myExtruPoly = globalExtruMesh.GetOutlines(viewport); foreach (Polyline poly in myExtruPoly) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.Brep: Rhino.Geometry.Point3d myBrepCentroid = ((Brep)foundObject1.Geometry).GetBoundingBox(true).Center; ce1 = myBrepCentroid; Mesh[] meshes = Rhino.Geometry.Mesh.CreateFromBrep((Brep)foundObject1.Geometry); Mesh globalMesh = new Rhino.Geometry.Mesh(); foreach (Mesh m in meshes) { globalMesh.Append(m); } Polyline[] myPolys2 = globalMesh.GetOutlines(viewport); foreach (Polyline poly in myPolys2) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = foundObject1.Geometry as Rhino.Geometry.Mesh; Rhino.Geometry.Point3d myMeshCentroid = mesh.GetBoundingBox(true).Center; ce1 = myMeshCentroid; Polyline[] meshOutline = mesh.GetOutlines(viewport); foreach (Polyline poly in meshOutline) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Red, 6); } break; case Rhino.DocObjects.ObjectType.TextDot: // todo break; case Rhino.DocObjects.ObjectType.Annotation: // todo break; } Rhino.Geometry.Line graphEdge = new Rhino.Geometry.Line(); graphEdge.From = ce0; graphEdge.To = ce1; e.Display.DrawLineArrow(graphEdge, System.Drawing.Color.DarkRed, 7, 4); } } e.Display.EnableDepthWriting(true); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobjectIndex) { if (IntPtr.Zero == pGeometry) { return(null); } var type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry); if (type < 0) { return(null); } GeometryBase rc = null; switch (type) { case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Curve: //1 rc = new Curve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsCurve: //2 rc = new NurbsCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolyCurve: // 3 rc = new PolyCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolylineCurve: //4 rc = new PolylineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ArcCurve: //5 rc = new ArcCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_LineCurve: //6 rc = new LineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Mesh: //7 rc = new Mesh(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Point: //8 rc = new Point(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_TextDot: //9 rc = new TextDot(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Surface: //10 rc = new Surface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Brep: //11 rc = new Brep(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsSurface: //12 rc = new NurbsSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_RevSurface: //13 rc = new RevSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PlaneSurface: //14 rc = new PlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ClippingPlaneSurface: //15 rc = new ClippingPlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Hatch: // 17 rc = new Hatch(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SumSurface: //19 rc = new SumSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepFace: //20 { int faceindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex); if (ptr_brep != IntPtr.Zero && faceindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Faces[faceindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepEdge: // 21 { int edgeindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex); if (ptr_brep != IntPtr.Zero && edgeindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Edges[edgeindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_InstanceReference: // 23 rc = new InstanceReferenceGeometry(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Extrusion: //24 rc = new Extrusion(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointCloud: // 26 rc = new PointCloud(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DetailView: // 27 rc = new DetailView(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Light: //32 rc = new Light(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointGrid: //33 rc = new Point3dGrid(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_MorphControl: //34 rc = new MorphControl(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepLoop: //35 { int loopindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex); if (ptr_brep != IntPtr.Zero && loopindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Loops[loopindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepTrim: // 36 { int trimindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex); if (ptr_brep != IntPtr.Zero && trimindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Trims[trimindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Leader: // 38 rc = new Leader(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SubD: // 39 rc = new SubD(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimLinear: //40 rc = new LinearDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimAngular: //41 rc = new AngularDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimRadial: //42 rc = new RadialDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimOrdinate: //43 rc = new OrdinateDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Centermark: //44 rc = new Centermark(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Text: //45 rc = new TextEntity(pGeometry, parent); break; default: rc = new UnknownGeometry(pGeometry, parent, subobjectIndex); break; } return(rc); }
/***************************************************/ 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 void DrawForeground(DrawEventArgs e) { base.DrawForeground(e); if (Edges.Count > 0) { System.Drawing.Color colorKid = System.Drawing.Color.LightCoral; foreach (List <Guid> li in Edges) { RhinoObject foundObject0 = Rhino.RhinoDoc.ActiveDoc.Objects.Find(li[0]); RhinoObject foundObject1 = Rhino.RhinoDoc.ActiveDoc.Objects.Find(li[1]); Rhino.Geometry.Point3d ce0 = new Rhino.Geometry.Point3d(); Rhino.Geometry.Point3d ce1 = new Rhino.Geometry.Point3d(); switch (foundObject0.ObjectType) { case Rhino.DocObjects.ObjectType.Point: ce0 = ((Rhino.Geometry.Point)foundObject0.Geometry).Location; break; case Rhino.DocObjects.ObjectType.Curve: Rhino.Geometry.Curve myCurve = (Rhino.Geometry.Curve)foundObject0.Geometry; myCurve.Domain = new Rhino.Geometry.Interval(0, 1); ce0 = myCurve.PointAtNormalizedLength(0.5); break; case Rhino.DocObjects.ObjectType.Extrusion: Rhino.Geometry.Extrusion myExtru = (Rhino.Geometry.Extrusion)foundObject0.Geometry; Rhino.Geometry.Point3d myExtruCentroid = Rhino.Geometry.AreaMassProperties.Compute(myExtru.ToBrep()).Centroid; ce0 = myExtruCentroid; break; case Rhino.DocObjects.ObjectType.Brep: Rhino.Geometry.Point3d myBrepCentroid = ((Brep)foundObject0.Geometry).GetBoundingBox(true).Center; ce0 = myBrepCentroid; break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = foundObject0.Geometry as Rhino.Geometry.Mesh; Rhino.Geometry.Point3d myMeshCentroid = mesh.GetBoundingBox(true).Center; ce0 = myMeshCentroid; break; case Rhino.DocObjects.ObjectType.TextDot: // todo break; case Rhino.DocObjects.ObjectType.Annotation: // todo break; } switch (foundObject1.ObjectType) { case Rhino.DocObjects.ObjectType.Point: ce1 = ((Rhino.Geometry.Point)foundObject1.Geometry).Location; break; case Rhino.DocObjects.ObjectType.Curve: Rhino.Geometry.Curve myCurve = (Rhino.Geometry.Curve)foundObject1.Geometry; myCurve.Domain = new Rhino.Geometry.Interval(0, 1); ce1 = myCurve.PointAtNormalizedLength(0.5); break; case Rhino.DocObjects.ObjectType.Extrusion: Rhino.Geometry.Extrusion myExtru = (Rhino.Geometry.Extrusion)foundObject1.Geometry; Rhino.Geometry.Point3d myExtruCentroid = Rhino.Geometry.AreaMassProperties.Compute(myExtru.ToBrep()).Centroid; ce1 = myExtruCentroid; break; case Rhino.DocObjects.ObjectType.Brep: Rhino.Geometry.Point3d myBrepCentroid = ((Brep)foundObject1.Geometry).GetBoundingBox(true).Center; ce1 = myBrepCentroid; break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = foundObject1.Geometry as Rhino.Geometry.Mesh; Rhino.Geometry.Point3d myMeshCentroid = mesh.GetBoundingBox(true).Center; ce1 = myMeshCentroid; break; case Rhino.DocObjects.ObjectType.TextDot: // todo break; case Rhino.DocObjects.ObjectType.Annotation: // todo break; } Rhino.Geometry.Line graphEdge = new Rhino.Geometry.Line(); graphEdge.From = ce0; graphEdge.To = ce1; e.Display.DrawLine(graphEdge, Color.Orange, 4); } } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
/// <summary> /// Draw the specified extrusion as a surface wireframe /// </summary> /// <param name="extrusion"></param> /// <remarks>TODO: Replace with shaded drawing method</remarks> public void Draw(RC.Extrusion extrusion) { Display.DrawSurface(extrusion, Color.Black, 1); }