//////////////////////////////////////////////////////////////////////////////////// ///Need to Clean up here............................................................ //////////////////////////////////////////////////////////////////////////////////// public T EnsureUnit_test <T>(object rhGeo) { GeometryBase geo = rhGeo as GeometryBase; if (targetUnit == baseUnit) { return((T)Convert.ChangeType(geo, typeof(T))); } else { if (baseUnit == "Meters" && targetUnit == "Feet") { geo.Transform(Transform.Scale(Point3d.Origin, 3.280841666667)); return((T)Convert.ChangeType(rhGeo, typeof(T))); } else if (baseUnit == "Feet" && targetUnit == "Meters") { geo.Transform(Transform.Scale(Point3d.Origin, 0.304800164592)); return((T)Convert.ChangeType(rhGeo, typeof(T))); } else { return(default(T)); } } }
public virtual void Transform(Transform x) { BasePlane.Transform(x); if (Geo != null) { Geo.Transform(x); } }
/// <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) { GeometryBase G = null; if (!DA.GetData(0, ref G)) { return; } if (G == null) { return; } Point3d O = new Point3d(); Point3d X = new Point3d(); Point3d Y = new Point3d(); if (!DA.GetData(1, ref O)) { return; } if (!DA.GetData(2, ref X)) { return; } if (!DA.GetData(3, ref Y)) { return; } Point3d Ot = new Point3d(); Point3d Xt = new Point3d(); Point3d Yt = new Point3d(); if (!DA.GetData(4, ref Ot)) { return; } if (!DA.GetData(5, ref Xt)) { return; } if (!DA.GetData(6, ref Yt)) { return; } Plane pA = new Plane(O, X, Y); Plane pB = new Plane(Ot, Xt, Yt); Transform x = Transform.PlaneToPlane(pA, pB); G.Transform(x); DA.SetData(0, G); DA.SetData(1, x); }
public object EnsureUnit_test(object rhGeo) { GeometryBase geo = rhGeo as GeometryBase; if (geo == null) { return(null); } if (targetUnit != baseUnit) { if (baseUnit == "Meters" && targetUnit == "Feet") { geo.Transform(Transform.Scale(Point3d.Origin, 3.280841666667)); } else if (baseUnit == "Feet" && targetUnit == "Meters") { geo.Transform(Transform.Scale(Point3d.Origin, 0.304800164592)); } } return(geo); }
/// <summary> /// Extract bounding frames to slice a given geometry. /// </summary> /// <param name="G"></param> /// <param name="XSpan"></param> /// <param name="YSpan"></param> /// <param name="ZSpan"></param> /// <param name="DXSpan"></param> /// <param name="DYSpan"></param> /// <param name="AngleDegrees"></param> /// <returns></returns> public static List <List <Plane> > BoundingFrames(GeometryBase G, double XSpan, double YSpan, double ZSpan, double DXSpan, double DYSpan, double AngleDegrees = 45.0) { // Nono.Util // BoundingFrames // Nono Martínez Alonso (nono.ma) // 160622, Autodesk Generative Design List <List <Plane> > Frames = new List <List <Plane> >(); // 1. Default BoundingBox BoundingBox bb = G.GetBoundingBox(true); Point3d[] corners = bb.GetCorners(); Line XLine = new Line(corners[0], corners[1]); Line YLine = new Line(corners[0], corners[3]); Line ZLine = new Line(corners[0], corners[4]); List <Plane> XFrames = new List <Plane>(); List <Plane> YFrames = new List <Plane>(); List <Plane> ZFrames = new List <Plane>(); // X Frames if (XSpan > 0) { double XAmount = Math.Floor(XLine.Length / XSpan); double XStep = XLine.Length / XAmount; double Xt = 0; for (double i = 0; i <= XAmount; i++) { Plane pl; Xt = i * XStep / XLine.Length; XLine.ToNurbsCurve().PerpendicularFrameAt(Xt, out pl); XFrames.Add(pl); } } // Y Frames if (YSpan > 0) { double YAmount = Math.Floor(YLine.Length / YSpan); double YStep = YLine.Length / YAmount; double Yt = 0; for (double i = 0; i <= YAmount; i++) { Plane pl; Yt = i * YStep / YLine.Length; YLine.ToNurbsCurve().PerpendicularFrameAt(Yt, out pl); YFrames.Add(pl); } } // Z Frames double ZAmount = ZLine.Length / ZSpan; for (double i = 0; i <= ZAmount; i++) { Plane pl; ZLine.ToNurbsCurve().PerpendicularFrameAt(i * ZSpan / ZLine.Length, out pl); ZFrames.Add(pl); } // 2. Diagonal BoundingBox Transform rotate = Transform.Rotation(-V2GMath.DEGREES_TO_RADIANS * AngleDegrees, new Vector3d(0, 0, 1), bb.Center); Transform rotateBack = Transform.Rotation(V2GMath.DEGREES_TO_RADIANS * AngleDegrees, new Vector3d(0, 0, 1), bb.Center); G.Transform(rotate); BoundingBox Dbb = G.GetBoundingBox(true); Point3d DbbCenter = Dbb.Center; Point3d[] Dcorners = Dbb.GetCorners(); Line DXLine = new Line(Dcorners[0], Dcorners[1]); Line DYLine = new Line(Dcorners[0], Dcorners[3]); List <Plane> DXFrames = new List <Plane>(); List <Plane> DYFrames = new List <Plane>(); // DX Frames if (DXSpan > 0) { double DXAmount = Math.Floor(DXLine.Length / DXSpan); double DXStep = DXLine.Length / DXAmount; double DXt = 0; for (double i = 0; i <= DXAmount; i++) { Plane pl; DXt = i * DXStep / DXLine.Length; DXLine.ToNurbsCurve().PerpendicularFrameAt(DXt, out pl); pl.Transform(rotateBack); DXFrames.Add(pl); } } // DY Frames if (DYSpan > 0) { double DYAmount = Math.Floor(DYLine.Length / DYSpan); double DYStep = DYLine.Length / DYAmount; double DYt = 0; for (double i = 0; i <= DYAmount; i++) { Plane pl; DYt = i * DYStep / DYLine.Length; DYLine.ToNurbsCurve().PerpendicularFrameAt(DYt, out pl); pl.Transform(rotateBack); DYFrames.Add(pl); } } Frames.Add(XFrames); Frames.Add(YFrames); Frames.Add(ZFrames); Frames.Add(DXFrames); Frames.Add(DYFrames); return(Frames); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //Pick curve for chain GetObject getCurve = new GetObject(); getCurve.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getCurve.SetCommandPrompt("Select curve for chain"); var res = getCurve.Get(); Rhino.DocObjects.ObjRef objref = getCurve.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } curve = objref.Curve(); if (curve == null) { return(Result.Failure); } obj.Select(false); //Pick object for chain (instance) //pick objekt to orient GetObject go = new GetObject(); go.SetCommandPrompt("Select chain element."); go.SubObjectSelect = true; go.DeselectAllBeforePostSelect = false; //go.GroupSelect = true; //go.GetMultiple(1, -1); go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef objref1 = go.Object(0); Rhino.DocObjects.RhinoObject obj1 = objref1.Object(); GeometryBase obj1Base = obj1.Geometry; int obCount = go.ObjectCount; string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); //create block instance and plane for instance Rhino.Input.Custom.GetPoint gp1 = new Rhino.Input.Custom.GetPoint(); gp1.SetCommandPrompt("Center point to orient from"); gp1.Get(); if (gp1.CommandResult() != Rhino.Commands.Result.Success) { return(gp1.CommandResult()); } Point3d pt1 = gp1.Point(); Rhino.Input.Custom.GetPoint gp2 = new Rhino.Input.Custom.GetPoint(); gp2.SetCommandPrompt("Point for orientation"); gp2.DrawLineFromPoint(pt1, false); gp2.Get(); if (gp2.CommandResult() != Rhino.Commands.Result.Success) { return(gp2.CommandResult()); } Point3d pt2 = gp2.Point(); Vector3d vt1 = pt2 - pt1; sourcePlane = new Plane(pt1, vt1); Plane originPlane = new Plane(Point3d.Origin, vt1); Transform bform = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane); obj1Base.Transform(bform); GeometryBase[] obj1List = new GeometryBase[1] { obj1Base }; var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List); //orient instances along curve List <Guid> chainBlocks = new List <Guid>(); Guid chainBlock; while (true) { foreach (var block in chainBlocks) { doc.Objects.Delete(block, false); } chainBlocks = new List <Guid>(); double curveLength = curve.GetLength(); double curveDivide = curveLength / chainDis; int curveDivideInt = Convert.ToInt32(curveDivide); for (int ic = 0; ic < curveDivideInt; ic++) { Point3d insertPoint = curve.PointAtLength(chainDis * ic); Vector3d insertVec = curve.PointAtLength(chainDis * ic + 1) - curve.PointAtLength(chainDis * ic - 1); Plane targetPlane = new Plane(insertPoint, insertVec); var xvec = targetPlane.XAxis; if (xvec.Z != 0) { targetPlane.Rotate(Math.PI / 2, insertVec); } var yvec = targetPlane.YAxis; if (yvec.Z < 0) { targetPlane.Rotate(Math.PI, insertVec); } if (ic % 2 == 0) { targetPlane.Rotate(Math.PI / 2, insertVec); } targetPlane.Rotate(axisOffsetRadiant, insertVec); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, targetPlane); chainBlock = doc.Objects.AddInstanceObject(orientBlock, xform); chainBlocks.Add(chainBlock); } doc.Views.Redraw(); GetOption gd = new GetOption(); gd.SetCommandPrompt("Set distance between element centers in mm and rotation offset in degree. Press enter to accept."); var dis = new Rhino.Input.Custom.OptionDouble(chainDis); var axisOffset = new Rhino.Input.Custom.OptionInteger(chainAxisOffset); gd.AddOptionDouble("distance", ref dis); gd.AddOptionInteger("rotation", ref axisOffset); gd.AcceptNothing(true); var resdis = gd.Get(); if (resdis == GetResult.Nothing) { break; } chainDis = dis.CurrentValue; chainAxisOffset = axisOffset.CurrentValue; axisOffsetRadiant = chainAxisOffset * (Math.PI / 180); } int index = doc.Groups.Add(chainBlocks); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //pick surface to orient to or block instance to relocate GetObject gs = new Rhino.Input.Custom.GetObject(); gs.SetCommandPrompt("Surface to orient new object on or BlockInstance to move"); gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.InstanceReference; gs.SubObjectSelect = true; gs.DeselectAllBeforePostSelect = false; gs.OneByOnePostSelect = true; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } Rhino.DocObjects.ObjRef objref = gs.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } surface = objref.Surface(); //relocate block instance if (surface == null) { Rhino.DocObjects.InstanceObject instance1 = objref.Object() as Rhino.DocObjects.InstanceObject; instancePoint = instance1.InsertionPoint; double g, h; surface2.ClosestPoint(instancePoint, out g, out h); var instanceDirection = surface2.NormalAt(g, h); instancePlane = new Plane(instancePoint, instanceDirection); Rhino.Input.Custom.GetPoint gpss = new Rhino.Input.Custom.GetPoint(); gpss.SetCommandPrompt("Point on surface to orient to"); gpss.Constrain(surface2, false); gpss.DynamicDraw += RefObjDraw; gpss.Tag = instance1; gpss.Get(); if (gpss.CommandResult() != Rhino.Commands.Result.Success) { return(gpss.CommandResult()); } Point3d ptss = gpss.Point(); surface2.ClosestPoint(ptss, out g, out h); var direction1 = surface2.NormalAt(g, h); Plane pl11 = new Plane(ptss, direction1); Transform iform = Rhino.Geometry.Transform.PlaneToPlane(instancePlane, pl11); doc.Objects.Transform(instance1, iform, true); return(Result.Success); } obj.Select(false); //pick objekt to orient var copy = new Rhino.Input.Custom.OptionToggle(false, "No", "Yes"); GetObject go = new GetObject(); go.SetCommandPrompt("Select object to orient."); go.AddOptionToggle("Copy", ref copy); go.SubObjectSelect = true; go.DeselectAllBeforePostSelect = false; go.GroupSelect = true; for (; ;) { var res = go.GetMultiple(1, -1); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } if (res == GetResult.Option) { copyBol = copy.CurrentValue; continue; } if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } break; } int obCount = go.ObjectCount; string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); //create block instance and plane for instance Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Point to orient from"); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } Vector3d vt1 = new Vector3d(0, 0, 1); Point3d pt1 = gp.Point(); sourcePlane = new Plane(pt1, vt1); Plane originPlane = new Plane(Point3d.Origin, vt1); Transform bform = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane); //block instance GeometryBase[] obj1List = new GeometryBase[obCount]; List <Brep> opList = new List <Brep>(); for (int igo = 0; igo < obCount; igo++) { Rhino.DocObjects.ObjRef objref1 = go.Object(igo); Rhino.DocObjects.RhinoObject obj1 = objref1.Object(); if (obj == null) { return(Result.Failure); } obj.Select(false); Rhino.Geometry.Brep opItem = objref1.Brep(); opList.Add(opItem); GeometryBase obj1Base = obj1.Geometry; obj1Base.Transform(bform); obj1List[igo] = obj1Base; } var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List); //get all go.Objects to .Tag Brep[] op = new Brep[obCount]; op = Brep.CreateBooleanUnion(opList, 0.01); Brep od = new Brep(); od = op[0]; var odGuid = doc.Objects.AddBrep(od); Rhino.DocObjects.ObjRef objref2 = new Rhino.DocObjects.ObjRef(odGuid); Rhino.DocObjects.RhinoObject objDrw = objref2.Object(); //orient plane to surface if (copyBol) { while (true) { Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint(); gps.SetCommandPrompt("Point on surface to orient to. Press enter when done."); gps.Constrain(surface, false); gps.AcceptNothing(true); gps.DynamicDraw += RefObjDraw; gps.Tag = objDrw; var res = gps.Get(); if (res == GetResult.Nothing) { break; } //else if (gps.CommandResult() != Rhino.Commands.Result.Success) // return gps.CommandResult(); Point3d pts = gps.Point(); double u, v; surface.ClosestPoint(pts, out u, out v); Vector3d direction = surface.NormalAt(u, v); Plane pl1 = new Plane(pts, direction); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1); doc.Objects.AddInstanceObject(orientBlock, xform); doc.Objects.Delete(objDrw); } copyBol = false; } else { Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint(); gps.SetCommandPrompt("Point on surface to orient to"); gps.Constrain(surface, false); gps.DynamicDraw += RefObjDraw; gps.Tag = objDrw; gps.Get(); if (gps.CommandResult() != Rhino.Commands.Result.Success) { return(gps.CommandResult()); } Point3d pts = gps.Point(); double u, v; surface.ClosestPoint(pts, out u, out v); Vector3d direction = surface.NormalAt(u, v); Plane pl1 = new Plane(pts, direction); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1); doc.Objects.AddInstanceObject(orientBlock, xform); doc.Objects.Delete(objDrw); } surface2 = surface; return(Result.Success); }