public static List <Curve> LinesToCircles(List <Curve> x, int divisions = 10, double radius = 25) { var crvs = new List <Curve>(); var lns = new List <Curve>(); foreach (Curve c in x) { // Print(c.SpanCount.ToString()); if (!c.IsLinear(0.01) || ((c.SpanCount + 1) > 2)) { crvs.Add(c); } else { Plane pl0; c.PerpendicularFrameAt(0, out pl0); lns.Add(PolylineUtil.Polygon(divisions, radius, pl0).ToNurbsCurve()); Plane pl1; c.PerpendicularFrameAt(1, out pl1); lns.Add(PolylineUtil.Polygon(divisions, radius, pl1).ToNurbsCurve()); } } crvs.AddRange(lns); return(crvs); }
public Panel(Polyline p0, Polyline p1) { this.contourNoJoints = new Polyline[] { new Polyline(p0), new Polyline(p1) }; this.contour = new Polyline[] { new Polyline(p0), new Polyline(p1) }; mesh = Mesh.CreateFromClosedPolyline(PolylineUtil.tweenPolylines(new Polyline(p0), new Polyline(p1))); this.planeOffset0 = p0.plane(); this.planeOffset1 = p1.plane(); this.plane = new Plane((planeOffset0.Origin + planeOffset1.Origin) * 0.5, planeOffset0.XAxis, planeOffset0.YAxis); }
/// <summary> /// Get Ngon Center /// </summary> /// <param name="mesh"></param> /// <param name="ngon"></param> /// <returns></returns> public static Point3d _FCenter(this Mesh M, int F) { uint[] vertices = M.Ngons.GetNgon(F).BoundaryVertexIndexList(); Polyline outline = new Polyline(); foreach (int v in vertices) { outline.Add(M.Vertices[v]); } return(PolylineUtil.CenterPoint(outline)); }
public static Polyline ZigZagFromRectangle(Rectangle3d rec, double step, double scale = 0.9) { Polyline pline = new Polyline(); double step_ = Math.Max(step * 1.5, scale); Rectangle3d recShrink = new Rectangle3d(rec.Plane, new Interval(-(rec.Width * 0.5) + 0, (rec.Width * 0.5) - 0), new Interval(-(rec.Height * 0.5) + step_, (rec.Height * 0.5) - step_)); int divisions = (int)MathUtil.Constrain(recShrink.Width / step, 2, 500); divisions += divisions % 2; Polyline zz = PolylineUtil.ZigZag(recShrink.ToPolyline(), false, step); return(zz); }
public static Mesh[] ProjectPairsMesh(this Mesh mesh, double value, ref Polyline[][] plinesProjected) { int n = (int)(mesh.Ngons.Count * 0.5); Polyline[][] p = new Polyline[n][]; Plane[] pl = mesh.GetNgonPlanes(); Polyline[] polys = mesh.GetPolylines(); Mesh[] m = new Mesh[n]; uint[][] id = mesh.GetNGonsBoundaries(); for (int i = 0; i < n; i++) { p[i] = new[] { new Polyline(), new Polyline() }; for (int j = 0; j < id[i].Length; j++) { Line temp = new Line(mesh.Vertices[(int)id[i][j]], mesh.Vertices[(int)id[i + n][j]]); double t1, t2; // polys[i].RemoveAt(0); // polys[i + n].RemoveAt(0); Plane plane0 = Plane.Unset; Plane plane1 = Plane.Unset; Plane.FitPlaneToPoints(polys[i], out plane0); Plane.FitPlaneToPoints(polys[i + n], out plane1); Rhino.Geometry.Intersect.Intersection.LinePlane(temp, plane0, out t1); Rhino.Geometry.Intersect.Intersection.LinePlane(temp, plane1, out t2); if (value < 1 && value >= 0) { p[i][0].Add(temp.PointAt(MathUtil.Lerp(0, t1, value))); p[i][1].Add(temp.PointAt(MathUtil.Lerp(1, t2, value))); } else { p[i][0].Add(temp.PointAt(t1)); p[i][1].Add(temp.PointAt(t2)); } } p[i][0].Close(); p[i][1].Close(); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(p[i][0]); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(p[i][1]); m[i] = PolylineUtil.Loft(p[i], 0); } plinesProjected = p; return(m); }
protected override void SolveInstance(IGH_DataAccess DA) { Curve curve = DA.Fetch<Curve>("Poly"); double t = DA.Fetch<double>("Chamfer"); Polyline polyline; if (curve.TryGetPolyline(out polyline)) { DA.SetData(0, PolylineUtil.Chamfer(polyline, t)); } }
//public static Mesh[] ProjectPairsMesh(this Mesh mesh, double value) { // int n = (int)(mesh.Ngons.Count * 0.5); // Polyline[][] p = new Polyline[n][]; // Plane[] pl = mesh.GetNgonPlanes(); // Mesh[] m = new Mesh[n]; // uint[][] id = mesh.GetNGonsBoundaries(); // for (int i = 0; i < n; i++) { // p[i] = new[] { new Polyline(), new Polyline() }; // for (int j = 0; j < id[i].Length; j++) { // Line temp = new Line(mesh.Vertices[(int)id[i][j]], mesh.Vertices[(int)id[i + n][j]]); // Rhino.Geometry.Intersect.Intersection.LinePlane(temp, pl[i], out double t1); // Rhino.Geometry.Intersect.Intersection.LinePlane(temp, pl[i + n], out double t2); // if (value < 1 && value >= 0) { // p[i][0].Add(temp.PointAt(MathUtil.Lerp(0, t1, value))); // p[i][1].Add(temp.PointAt(MathUtil.Lerp(1, t2, value))); // } else { // p[i][0].Add(temp.PointAt(t1)); // p[i][1].Add(temp.PointAt(t2)); // } // } // p[i][0].Close(); // p[i][1].Close(); // m[i] = PolylineUtil.Loft(p[i], 0); // } // return m; //} public static Mesh[] ProjectPairsMesh(this Mesh mesh0, Mesh mesh1, double value) { int n = (int)(mesh0.Ngons.Count); Polyline[][] p = new Polyline[n][]; Plane[] pl0 = mesh0.GetNgonPlanes(); Plane[] pl1 = mesh1.GetNgonPlanes(); Mesh[] m = new Mesh[n]; uint[][] id = mesh0.GetNGonsBoundaries(); for (int i = 0; i < n; i++) { p[i] = new[] { new Polyline(), new Polyline() }; for (int j = 0; j < id[i].Length; j++) { Line temp = new Line(mesh0.Vertices[(int)id[i][j]], mesh1.Vertices[(int)id[i][j]]); Rhino.Geometry.Intersect.Intersection.LinePlane(temp, pl0[i], out double t1); Rhino.Geometry.Intersect.Intersection.LinePlane(temp, pl1[i], out double t2); if (value < 1 && value >= 0) { p[i][0].Add(temp.PointAt(MathUtil.Lerp(0, t1, value))); p[i][1].Add(temp.PointAt(MathUtil.Lerp(1, t2, value))); } else { p[i][0].Add(temp.PointAt(t1)); p[i][1].Add(temp.PointAt(t2)); } } p[i][0].Close(); p[i][1].Close(); m[i] = PolylineUtil.Loft(p[i], 0); } return(m); }
protected override void SolveInstance(IGH_DataAccess DA) { try { //////////////////////////////////////////////////////////////////// //Inputs Grasshopper Mesh M = DA.Fetch <Mesh>("Mesh"); DataTree <Polyline> PanelOutlines = DA.FetchTree <GH_Curve>("Panels").ToPolylineDT(); DataTree <Vector3d> EVec = DA.FetchTree <GH_Vector>("EdgeVectors").ToDT(); int D = DA.Fetch <int>("JointDiv"); double L = DA.Fetch <double>("JointLen"); double H = DA.Fetch <double>("JointHei"); double W = DA.Fetch <double>("JointThi"); bool Center = DA.Fetch <bool>("Center"); bool Finger = DA.Fetch <bool>("Finger"); double Custom = DA.Fetch <double>("Custom"); DataTree <Polyline> CChamfer = new DataTree <Polyline>(); int iterations = DA.Fetch <int>("Iterations"); List <int> sequence = DA.FetchList <int>("Sequence"); List <double> textSize = DA.FetchList <double>("TextScale"); if (textSize.Count < 6) { textSize = new List <double> { 20, 10, 10, 0.5, 0.75, 10 } } ; DataTree <Panel> PanelGroups = DA.FetchTree <GH_Curve>("Panels").ToPanelsDT(); DataTree <Panel> JointGroups = new DataTree <Panel>(); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //Inputs Local int divisions = Math.Max(1, D); double jointLength = L;//Math.Max(0.1, L); double height = Math.Max(0.1, H); double width = Math.Max(0.1, W); int[][] tv = M.GetNGonsTopoBoundaries(); int[][] fe = M.GetNGonFacesEdges(tv); HashSet <int> e = M.GetAllNGonEdges(tv); Dictionary <int, int[]> efDict = M.GetFE(e, false); Point3d[] centers = M.GetNGonCenters(); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Insertion vectors DataTree <Vector3d> EV = M.insertionVectors(Center, EVec); //////////////////////////////////////////////////////////////////// DataTree <Polyline> diagonalConnections = new DataTree <Polyline>(); //DataTree<Polyline> recJoints = new DataTree<Polyline>(); //Iterate insertion edges Dictionary <int, int> meshEdgeDict = new Dictionary <int, int>(); for (int i = 0; i < EV.BranchCount; i++) // EV.BranchCount { int meshEdge = EV.Path(i).Indices[0];//mesh edge is used as dataTree branch meshEdgeDict.Add(meshEdge, i); if (efDict[meshEdge].Length != 2) { continue; } int f0 = efDict[meshEdge][0]; int f1 = efDict[meshEdge][1]; //Divide line into points and create a planes on these point, following insertion direction and average face normal Point3d[] pts = M.TopologyEdges.EdgeLine(meshEdge).InterpolateLine(divisions, false); for (int j = 0; j < pts.Length; j++) { JointGroups.Add(new Panel(new Plane(pts[j], EV.Branch(EV.Path(i))[0].UnitVector(), M.GetMeshEdgePerpDir(meshEdge))), EV.Path(i)); } //Construct joint outlines from planes //Iterate number of joints per edge for (int j = 0; j < pts.Length; j++) { JointGroups.Branch(EV.Path(i))[j].planeOffset0 = JointGroups.Branch(EV.Path(i))[j].plane.MovePlanebyAxis(W * 0.5); //offset planes JointGroups.Branch(EV.Path(i))[j].planeOffset1 = JointGroups.Branch(EV.Path(i))[j].plane.MovePlanebyAxis(-W * 0.5); //offset planes JointGroups.Branch(EV.Path(i))[j].planeRot = new Plane(pts[j], Vector3d.CrossProduct(EV.Branch(EV.Path(i))[0].UnitVector(), M.GetMeshEdgePerpDir(meshEdge)), M.GetMeshEdgePerpDir(meshEdge)); JointGroups.Branch(EV.Path(i))[j].planeRotOffset0 = JointGroups.Branch(EV.Path(i))[j].planeRot.MovePlanebyAxis(jointLength); //offset planes JointGroups.Branch(EV.Path(i))[j].planeRotOffset1 = JointGroups.Branch(EV.Path(i))[j].planeRot.MovePlanebyAxis(-jointLength); //offset plane JointGroups.Branch(EV.Path(i))[j].planeEdge = new Plane(pts[j], M.TopologyEdges.EdgeLine(meshEdge).Direction, M.GetMeshEdgePerpDir(meshEdge)); List <Plane> planesF0 = new List <Plane>(); List <Plane> planesF1 = new List <Plane>(); for (int k = 0; k < PanelGroups.Branch(f0).Count; k++) { planesF0.Add(PanelGroups.Branch(f0)[k].plane); planesF1.Add(PanelGroups.Branch(f1)[k].plane); } JointGroups.Branch(EV.Path(i))[j].planeF0 = PlaneUtil.AveragePlaneOrigin(planesF0); JointGroups.Branch(EV.Path(i))[j].planeF1 = PlaneUtil.AveragePlaneOrigin(planesF1); List <Plane> jointPlaneLoop = new List <Plane> { JointGroups.Branch(EV.Path(i))[j].planeRotOffset0, JointGroups.Branch(EV.Path(i))[j].planeF0.MovePlanebyAxis(height), JointGroups.Branch(EV.Path(i))[j].planeEdge, JointGroups.Branch(EV.Path(i))[j].planeF1.MovePlanebyAxis(height), //3 JointGroups.Branch(EV.Path(i))[j].planeRotOffset1, JointGroups.Branch(EV.Path(i))[j].planeF1.MovePlanebyAxis(-height), //5 JointGroups.Branch(EV.Path(i))[j].planeEdge, JointGroups.Branch(EV.Path(i))[j].planeF0.MovePlanebyAxis(-height), }; //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(JointGroups.Branch(EV.Path(i))[j].planeF1, new Interval(-20, 20), new Interval(-20, 20))); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(JointGroups.Branch(EV.Path(i))[j].planeF1, new Interval(-20, 20), new Interval(-20, 20))); JointGroups.Branch(EV.Path(i))[j].contourNoJoints[0] = PolylineUtil.PolylineFromPlanes(JointGroups.Branch(EV.Path(i))[j].planeOffset0, jointPlaneLoop); JointGroups.Branch(EV.Path(i))[j].contourNoJoints[1] = PolylineUtil.PolylineFromPlanes(JointGroups.Branch(EV.Path(i))[j].planeOffset1, jointPlaneLoop); JointGroups.Branch(EV.Path(i))[j].contour[0] = new Polyline(JointGroups.Branch(EV.Path(i))[j].contourNoJoints[0]); JointGroups.Branch(EV.Path(i))[j].contour[1] = new Polyline(JointGroups.Branch(EV.Path(i))[j].contourNoJoints[1]); } //Construct Cuts //Iterate number of joints per edge for (int j = 0; j < pts.Length; j++) { int localMeshEdgeF0 = Array.IndexOf(fe[f0], meshEdge); int localMeshEdgeF1 = Array.IndexOf(fe[f1], meshEdge); //Iterate number of panels and create cuts for (int k = 0; k < PanelGroups.Branch(f0).Count; k++) { Panel jointPanel = JointGroups.Branch(EV.Path(i))[j]; jointPanel.id = f0.ToString() + "-" + f1.ToString(); //if(f0==f1) // Rhino.RhinoApp.WriteLine(jointPanel.id); if (pts.Length > 1) { jointPanel.id += "-" + j.ToString(); } bool flag = f0 == 165 && f1 == 166; PanelGroups.Branch(f0)[k].CreateCut(localMeshEdgeF0, JointGroups.Branch(EV.Path(i))[j].planeOffset0, JointGroups.Branch(EV.Path(i))[j].planeOffset1, jointLength, ref jointPanel, flag); //, ref neiPanel, ref jointPanel); PanelGroups.Branch(f1)[k].CreateCut(localMeshEdgeF1, JointGroups.Branch(EV.Path(i))[j].planeOffset0, JointGroups.Branch(EV.Path(i))[j].planeOffset1, jointLength, ref jointPanel, flag); //, ref neiPanel, ref jointPanel); JointGroups.Branch(EV.Path(i))[j] = jointPanel; } } } for (int i = 0; i < JointGroups.BranchCount; i++) { for (int j = 0; j < JointGroups.Branch(i).Count; j++) { if (Custom > 0) { JointGroups.Branch(i)[j].ChangeJoint(Custom, 0); } else if (Custom < 0) { JointGroups.Branch(i)[j].ChangeJoint(Custom, 1, textSize[7]); } } } ////////////////////////Output var dtPlates = new DataTree <Polyline>(); var dtJoints = new DataTree <Polyline>(); var dtPlatesMid = new DataTree <Polyline>(); var dtJointsMid = new DataTree <Polyline>(); var dtPlatesPlanes = new DataTree <Plane>(); var dtJointsPlanes = new DataTree <Plane>(); var dtPlatesTxt = new DataTree <Curve>(); var dtJointsTxt = new DataTree <Curve>(); var dtPlatesLast = new DataTree <Polyline>(); var dtJointsLast = new DataTree <Polyline>(); var dtPlatesMidLast = new DataTree <Polyline>(); var dtJointsMidLast = new DataTree <Polyline>(); var dtPlatesPlanesLast = new DataTree <Plane>(); var dtJointsPlanesLast = new DataTree <Plane>(); var dtPlatesTxtLast = new DataTree <Curve>(); var dtJointsTxtLast = new DataTree <Curve>(); HashSet <int> jointSequence = new HashSet <int>(); HashSet <int> jointSequenceLast = new HashSet <int>(); int last = Math.Min(iterations, PanelGroups.BranchCount); int prev = Math.Max(0, last - (int)textSize[6]); for (int i = 0; i < last; i++) //Math.Min(iterations, sequence.Count) PanelGroups.BranchCount { for (int j = 0; j < fe[i].Length; j++) { bool seq = jointSequence.Add(fe[i][j]); if (i >= prev) { if (seq) { jointSequenceLast.Add(fe[i][j]); } } } for (int j = 0; j < PanelGroups.Branch(i).Count; j++) { dtPlates.Add(PanelGroups.Branch(i)[j].contour[0], new GH_Path(i, j)); dtPlates.Add(PanelGroups.Branch(i)[j].contour[1], new GH_Path(i, j)); dtPlatesMid.Add(PanelGroups.Branch(i)[j].MidContour(), new GH_Path(i, j)); if (i >= prev) { dtPlatesLast.Add(PanelGroups.Branch(i)[j].contour[0], new GH_Path(i, j)); dtPlatesLast.Add(PanelGroups.Branch(i)[j].contour[1], new GH_Path(i, j)); dtPlatesMidLast.Add(PanelGroups.Branch(i)[j].MidContour(), new GH_Path(i, j)); } Plane textPlane = PanelGroups.Branch(i)[j].planeOffset0; textPlane.Flip(); if (j == 1) { textPlane = PanelGroups.Branch(i)[j].planeOffset1; } dtPlatesPlanes.Add(textPlane, new GH_Path(i, j)); if (i >= prev) { dtPlatesPlanesLast.Add(textPlane, new GH_Path(i, j)); } string text = i.ToString() + "-" + j.ToString(); var txtCrv = Typewriter.Regular.Write(text, textPlane, textSize[0]); dtPlatesTxt.AddRange(txtCrv, new GH_Path(i, j)); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrv, new GH_Path(i, j)); } //for(int k = 0; k < PanelGroups.Branch(i)[j].contourNoJoints.Length; k++) { Line[] segments = PanelGroups.Branch(i)[j].contourNoJoints[j].GetSegments(); int counter = 0; foreach (Line l in segments) { int meshEdge = fe[i][counter]; int neiF = M.GetOppositeNgon(meshEdge, i); //Adjacent face plane Point3d origin = l.PointAt(textSize[3]); Vector3d xaxis = l.Direction; Vector3d yaxis = l.Direction; origin.Transform(Transform.Scale(textPlane.Origin, textSize[4])); yaxis.Rotate(Math.PI * 0.5, textPlane.ZAxis); Plane ePlane = new Plane(origin, xaxis, yaxis); var txtCrvF = Typewriter.Regular.Write(neiF.ToString(), ePlane, textSize[2]); dtPlatesTxt.AddRange(txtCrvF, new GH_Path(i, j)); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrvF, new GH_Path(i, j)); } //Mesh edge direction Line meshEdgeLine = M.TopologyEdges.EdgeLine(meshEdge); meshEdgeLine.Transform(Transform.Scale(meshEdgeLine.PointAt(0.5), textSize[4])); meshEdgeLine.Transform(Transform.Scale(textPlane.Origin, textSize[4])); //meshEdgeLine.Extend(-textSize[4], -textSize[4]); Plane e0Plane = new Plane(ePlane.ClosestPoint(meshEdgeLine.From), xaxis, yaxis); Plane e1Plane = new Plane(ePlane.ClosestPoint(meshEdgeLine.To), xaxis, yaxis); var txtCrvF0 = Typewriter.Regular.Write("I", e0Plane, textSize[2]); dtPlatesTxt.AddRange(txtCrvF0, new GH_Path(i, j)); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrvF0, new GH_Path(i, j)); } var txtCrvF1 = Typewriter.Regular.Write("II", e1Plane, textSize[2]); dtPlatesTxt.AddRange(txtCrvF1, new GH_Path(i, j)); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrvF1, new GH_Path(i, j)); } counter++; // } } } foreach (int meshEdge in jointSequence) { //for (int i = 0; i < Math.Min(iterations, sequence.Count); i++) {//JointGroups.BranchCount if (!meshEdgeDict.ContainsKey(meshEdge)) { continue; } int i = meshEdgeDict[meshEdge]; for (int j = 0; j < JointGroups.Branch(i).Count; j++) { dtJoints.Add(JointGroups.Branch(i)[j].contour[0], new GH_Path(meshEdge, j)); dtJoints.Add(JointGroups.Branch(i)[j].contour[1], new GH_Path(meshEdge, j)); dtJointsMid.Add(JointGroups.Branch(i)[j].MidContour(), new GH_Path(i, j)); dtJointsPlanes.Add(JointGroups.Branch(i)[j].planeOffset0, new GH_Path(meshEdge, j)); Plane planet = new Plane(JointGroups.Branch(i)[j].planeOffset0.Origin + JointGroups.Branch(i)[j].planeOffset0.YAxis * textSize[5], JointGroups.Branch(i)[j].planeOffset0.XAxis, JointGroups.Branch(i)[j].planeOffset0.YAxis); string text = JointGroups.Branch(i)[j].id; var txtCrv = Typewriter.Regular.Write(text, planet, textSize[1]); dtJointsTxt.AddRange(txtCrv, new GH_Path(meshEdge, j)); } } foreach (int meshEdge in jointSequenceLast) { //for (int i = 0; i < Math.Min(iterations, sequence.Count); i++) {//JointGroups.BranchCount if (!meshEdgeDict.ContainsKey(meshEdge)) { continue; } int i = meshEdgeDict[meshEdge]; for (int j = 0; j < JointGroups.Branch(i).Count; j++) { dtJointsLast.Add(JointGroups.Branch(i)[j].contour[0], new GH_Path(meshEdge, j)); dtJointsLast.Add(JointGroups.Branch(i)[j].contour[1], new GH_Path(meshEdge, j)); dtJointsMidLast.Add(JointGroups.Branch(i)[j].MidContour(), new GH_Path(i, j)); dtJointsPlanesLast.Add(JointGroups.Branch(i)[j].planeOffset0, new GH_Path(meshEdge, j)); Plane planet = new Plane(JointGroups.Branch(i)[j].planeOffset0.Origin + JointGroups.Branch(i)[j].planeOffset0.YAxis * textSize[5], JointGroups.Branch(i)[j].planeOffset0.XAxis, JointGroups.Branch(i)[j].planeOffset0.YAxis); string text = JointGroups.Branch(i)[j].id; var txtCrv = Typewriter.Regular.Write(text, planet, textSize[1]); dtJointsTxtLast.AddRange(txtCrv, new GH_Path(meshEdge, j)); } } DA.SetDataTree(0, dtPlates); DA.SetDataTree(1, dtJoints); DA.SetDataTree(2, dtPlatesMid); DA.SetDataTree(3, dtJointsMid); DA.SetDataTree(4, dtPlatesPlanes); DA.SetDataTree(5, dtJointsPlanes); DA.SetDataTree(6, dtPlatesTxt); DA.SetDataTree(7, dtJointsTxt); DA.SetDataTree(8, dtPlatesLast); DA.SetDataTree(9, dtJointsLast); DA.SetDataTree(10, dtPlatesMidLast); DA.SetDataTree(11, dtJointsMidLast); DA.SetDataTree(12, dtPlatesPlanesLast); DA.SetDataTree(13, dtJointsPlanesLast); DA.SetDataTree(14, dtPlatesTxtLast); DA.SetDataTree(15, dtJointsTxtLast); } catch (Exception e) { Rhino.RhinoApp.WriteLine(e.ToString()); } }
public Polyline MidContour() { return(PolylineUtil.tweenPolylines(contour[0], contour[1])); }
public static List <List <Polyline> > Miter(Mesh M, double D, double JointStep, double scale, GH_Structure <GH_Curve> additionalPlines) { if (additionalPlines.Branches.Count != 2) { return(null); } if (additionalPlines[0].Count != M.Ngons.Count || additionalPlines[1].Count != M.Ngons.Count) { return(null); } List <List <Polyline> > zzAll = new List <List <Polyline> >(); List <List <Line> > zzLinesAll = new List <List <Line> >(); List <List <Plane> > zzPlanesAll = new List <List <Plane> >(); Polyline[] plines = M.GetPolylines(); //Plane[] planes = M.GetNgonPlanes(); int[][] tv = M.GetNGonsTopoBoundaries(); int[][] fe = M.GetNGonFacesEdges(tv); HashSet <int> allE = M.GetAllNGonEdges(tv); int[][] ef = M.GetNgonsConnectedToNGonsEdges(allE, false); uint[][] finf = M.GetFacesInNGons(); int[] allEArray = allE.ToArray(); Dictionary <int, int> meNgonE = new Dictionary <int, int>(); for (int i = 0; i < allEArray.Length; i++) { meNgonE.Add(allEArray[i], i); } //Get planes Plane[] planes = new Plane[M.Ngons.Count]; for (int i = 0; i < additionalPlines[0].Count; i++) { Curve curve = additionalPlines[0][i].Value; curve.TryGetPolyline(out Polyline pline); planes[i] = pline.GetPlane(); } Line[] allEArrayLines = new Line[allEArray.Length]; Plane[] allEArrayBisector = new Plane[allEArray.Length]; for (int i = 0; i < M.Ngons.Count; i++) { zzAll.Add(new List <Polyline>()); zzPlanesAll.Add(new List <Plane>()); } //Get line segments and edge planes for (int i = 0; i < allEArray.Length; i++) { int me = allEArray[i]; int ne = meNgonE[me]; int[] edgeFaces = ef[ne]; if (edgeFaces.Length == 2) { //Rhino.RhinoApp.WriteLine(edgeFaces[0].ToString() + " " + edgeFaces[1].ToString()); int[] fe0 = fe[edgeFaces[0]]; int[] fe1 = fe[edgeFaces[1]]; int localID0 = Array.IndexOf(fe0, me); int localID1 = Array.IndexOf(fe1, me); //Get segments Curve curve = additionalPlines[0][edgeFaces[0]].Value; curve.TryGetPolyline(out Polyline pline0); curve = additionalPlines[1][edgeFaces[0]].Value; curve.TryGetPolyline(out Polyline pline1); Line l0 = PolylineUtil.tweenLine(pline0.SegmentAt(localID0), pline1.SegmentAt(localID0)); curve = additionalPlines[0][edgeFaces[1]].Value; curve.TryGetPolyline(out Polyline pline2); curve = additionalPlines[1][edgeFaces[1]].Value; curve.TryGetPolyline(out Polyline pline3); Line l1 = PolylineUtil.tweenLine(pline2.SegmentAt(localID1), pline3.SegmentAt(localID1)); //l0.Bake(); //l1.Bake(); l1.Flip(); allEArrayLines[ne] = PolylineUtil.tweenLine(l0, l1); Vector3d XAxis = allEArrayLines[ne].Direction; var pointsFit = new List <Point3d>(); pointsFit.AddRange(pline0.SegmentAt(localID0).ToP()); pointsFit.AddRange(pline1.SegmentAt(localID0).ToP()); pointsFit.AddRange(pline2.SegmentAt(localID1).ToP()); pointsFit.AddRange(pline3.SegmentAt(localID1).ToP()); Plane.FitPlaneToPoints(pointsFit, out Plane fitPlane); fitPlane.Rotate(Vector3d.VectorAngle(fitPlane.XAxis, XAxis, fitPlane), fitPlane.ZAxis); Point3d p0 = pline0.SegmentAt(localID0).PointAt(0.5); Point3d p1 = pline1.SegmentAt(localID0).PointAt(0.5); //Vector3d YAxis = (pline0.SegmentAt(localID0).PointAt(0.5) - pline1.SegmentAt(localID0).PointAt(0.5)) + (pline0.SegmentAt(localID1).PointAt(0.5) - pline1.SegmentAt(localID1).PointAt(0.5)); Plane plane = new Plane(allEArrayLines[ne].PointAt(0.5), XAxis, fitPlane.YAxis); allEArrayBisector[ne] = plane; //plane.Bake(1); //Create ZigZag Vector3d sideVec = Vector3d.CrossProduct(XAxis, plane.ZAxis); Rectangle3d rect = new Rectangle3d(new Plane(plane.Origin, plane.ZAxis, XAxis), new Interval(-D * 0.5, D * 0.5), new Interval(-allEArrayLines[ne].Length * 0.5, allEArrayLines[ne].Length * 0.5)); Polyline zigzag0 = ZigZagFromRectangle(rect, JointStep, scale); zzAll[edgeFaces[0]].Add(zigzag0); zzPlanesAll[edgeFaces[0]].Add(new Plane(rect.Plane)); //zigzag0.Bake(); //plane.Rotate(Math.PI,plane.ZAxis); rect = new Rectangle3d(new Plane(plane.Origin, -plane.ZAxis, -XAxis), new Interval(-D * 0.5, D * 0.5), new Interval(-allEArrayLines[ne].Length * 0.5, allEArrayLines[ne].Length * 0.5)); //rect.ToPolyline().Bake(); Polyline zigzag1 = ZigZagFromRectangle(rect, JointStep, scale); zzAll[edgeFaces[1]].Add(zigzag1); zzPlanesAll[edgeFaces[1]].Add(new Plane(rect.Plane)); //zzAll.Add(); //zigzag1.Bake(); } else { //int[] fe0 = fe[edgeFaces[0]]; //int localID0 = Array.IndexOf(fe0, me); ////Get segments //Curve curve = additionalPlines[0][edgeFaces[0]].Value; //curve.TryGetPolyline(out Polyline pline0); //curve = additionalPlines[1][edgeFaces[0]].Value; //curve.TryGetPolyline(out Polyline pline1); //Line l0 = PolylineUtil.tweenLine(pline0.SegmentAt(localID0), pline1.SegmentAt(localID0)); //allEArrayLines[ne] = l0; //Vector3d XAxis = allEArrayLines[ne].Direction; //Vector3d YAxis = (pline0.SegmentAt(localID0).PointAt(0.5) - pline1.SegmentAt(localID0).PointAt(0.5)) ; //Plane plane = new Plane(allEArrayLines[ne].PointAt(0.5), XAxis, YAxis); //allEArrayBisector[ne] = plane; ////plane.Bake(1); //Vector3d sideVec = Vector3d.CrossProduct(XAxis, plane.ZAxis); //Rectangle3d rect = new Rectangle3d(new Plane(plane.Origin, plane.ZAxis, XAxis ), new Interval(-D * 0.5, D * 0.5), new Interval(-allEArrayLines[ne].Length * 0.5, allEArrayLines[ne].Length * 0.5)); //Polyline zigzag = ZigZagFromRectangle(rect, JointStep, scale); ////zigzag.Bake(); } } ////Plane[][] bisePlanes; ////Plane[][] edgePlanes;//"ZY" ////M.GetEdgeAndBisectorPlanes(out bisePlanes, out edgePlanes); // for (int i = 0; i < plines.Length; i++) { // var zz = new List<Polyline>(); // var zzLines = new List<Line>(); // var zzPlanes = new List<Plane>(); // if (D != 0) { // Point3d center = M._Plane(i).Origin; // for (int j = 0; j < plines[i].Count - 1; j++) { // int e = fe[i][j]; // int[] faces = M.TopologyEdges.GetConnectedFaces(e); // int neiFace = faces[0]; // Vector3d normalDir = Vector3d.Zero; // if (faces.Length == 2) { // bool flag = false; // foreach (var ff in finf[i]) { // if (faces[0] == (int)ff) { // flag = true; // break; // } // } // neiFace = flag ? faces[1] : faces[0]; // normalDir = (M.FaceNormals[faces[1]] + M.FaceNormals[faces[0]]); // normalDir.Unitize(); // } else { // continue; // normalDir = (M.FaceNormals[faces[0]]); // normalDir.Unitize(); // } // Line l = plines[i].SegmentAt(j); // Vector3d dir = Vector3d.CrossProduct(M.FaceNormals[neiFace], l.Direction); // dir.Unitize(); // Point3d p0 = l.PointAt(0.5); // dir = -normalDir; // Vector3d sideVec = Vector3d.CrossProduct(l.Direction, normalDir); // Rectangle3d rect = new Rectangle3d(new Plane(l.Center(), sideVec, l.Direction), new Interval(-D * 0.5, D * 0.5), new Interval(-l.Length * 0.5, l.Length * 0.5)); // Polyline zigzag = ZigZagFromRectangle(rect, JointStep, scale); // //Project zigzag points to plane by direction of plane normal // for (int k = 0; k < zigzag.Count; k++) { // Line zzLine = new Line(zigzag[k], zigzag[k] + rect.Plane.ZAxis); // zigzag[k] = PlaneUtil.LinePlane(zzLine, planes[i]); // } // zzPlanes.Add(rect.Plane); // zz.Add(zigzag); // int sign = faces.Length == 2 ? -1 : -1; // //if (F) // // sign *= -1; // double distance = D * sign; // Polyline polyline = new Polyline() { l.From, l.To, l.To + dir * distance, l.From + dir * distance, l.From }; // }//for j // zzAll.Add(zz); // zzPlanesAll.Add(zzPlanes); // } //} //Add zigzag to panels //for (int i = 0; i < plines.Length; i++) { // plines[i].InsertPolyline(zzAll[i]); //} List <List <Polyline> > zzAllNew = new List <List <Polyline> >(); zzAllNew.Add(new List <Polyline>()); zzAllNew.Add(new List <Polyline>()); if (additionalPlines != null) { for (int i = 0; i < additionalPlines.Branches.Count; i++) { if (additionalPlines[i].Count != plines.Length) { continue; } for (int j = 0; j < additionalPlines[i].Count; j++) { //Cast to Polyline Curve curve = additionalPlines[i][j].Value; bool good = curve.TryGetPolyline(out Polyline aPline); if (good) { Plane plane = aPline.GetPlane(); for (int k = 0; k < zzAll[j].Count; k++) { Polyline zzPolyline = new Polyline(); for (int m = 0; m < zzAll[j][k].Count; m++) { Line zzLine = new Line(zzAll[j][k][m], zzAll[j][k][m] + zzPlanesAll[j][k].ZAxis); Point3d zzPoint = PlaneUtil.LinePlane(zzLine, plane); //zzPoint.Bake(); zzPolyline.Add(zzPoint); // } //zzPolyline.Bake(); aPline.InsertPolyline(zzPolyline); } //aPline.Bake(); //break; //additionalPlines[i][j] = new GH_Curve(new Polyline(aPline).ToNurbsCurve()); zzAllNew[i].Add(aPline); //zzAllNew[1].Add(aPline); } // } } //iterate of n-th layer of mesh. } //not null //zzAll.Clear(); return(zzAllNew); //return new List<List<Polyline>>() { additionalPlines[0], }; }
public DataTree <Polyline> Panels(NGonsCore.MeshProps p) { //Draw panels DataTree <Polyline> dtPlates = new DataTree <Polyline>(); for (int i = 0; i < p.M._countF(); i++) { Plane panel0 = p.fPl[i]; Plane panel1 = p.fPl[i].MovePlanebyAxis(-plateThickness); Plane panel2 = panel1.MovePlanebyAxis(plateThickness * 10); List <Plane> sidePlanes = new List <Plane>(); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0) { sidePlanes.Add(this[i, j].fcPl[0]); } else { int[] oppo = p.M._OppositeFE(i, j); Plane sidePlane = Plane.Unset; if (oppo[0] != -1) { Plane oppoPlane = this[oppo[0], oppo[1]].ePl; Plane ePl0 = oppoPlane; Plane ePl1 = new Plane(oppoPlane.Origin, oppoPlane.YAxis, oppoPlane.ZAxis); Plane left = p.fPl[i]; Plane right = p.fPl[oppo[0]]; Point3d originRight = PlaneUtil.PlanePlanePlane(ePl0, ePl1, left); Point3d originLeft = PlaneUtil.PlanePlanePlane(ePl0, ePl1, right); sidePlane = p.fePl[i][j].ChangeOrigin(originRight); } else { sidePlane = p.fePl[i][j]; } sidePlane = sidePlane.MovePlanebyAxis(offset0 * scale * extend, panel0.Origin); sidePlanes.Add(sidePlane); } } Polyline panelOutline0 = PolylineUtil.PolylineFromPlanes(panel0, sidePlanes); Polyline panelOutline1 = PolylineUtil.PolylineFromPlanes(panel1, sidePlanes); Polyline panelOutline2 = PolylineUtil.PolylineFromPlanes(panel2, sidePlanes); dtPlates.Add(panelOutline0, new Grasshopper.Kernel.Data.GH_Path(i)); dtPlates.Add(panelOutline1, new Grasshopper.Kernel.Data.GH_Path(i)); for (int j = 0; j < p.M._countE(i); j++) { int[] op = p.M._OppositeFE(i, j); if (this[i, j].isNexor != 0) { this[i, j].CNCtopProfileCuts.Add(panelOutline1); this[i, j].CNCtopProfileCuts.Add(panelOutline2); } if (op[0] != -1) { this[op[0], op[1]].CNCtopProfileCuts.Add(panelOutline1); this[op[0], op[1]].CNCtopProfileCuts.Add(panelOutline2); } } } return(dtPlates); List <Line> pipes = new List <Line>(); for (int i = 0; i < p.M._countF(); i++) { int[] fe = p.M._fe(i); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0 && !p.M.IsNaked(fe[j])) { Line line = this[i, j].line; line.Transform(Transform.Translation(this[i, j].ePl.YAxis * -movePipeAxis)); line = new Line(PlaneUtil.LinePlane(line, this[i, j].endPl0), PlaneUtil.LinePlane(line, this[i, j].endPl1)); line.Extend(0.2, 0.2); pipes.Add(line); } } } }
protected override void SolveInstance(IGH_DataAccess DA) { try { //////////////////////////////////////////////////////////////////// //Inputs Grasshopper Mesh M = DA.Fetch <Mesh>("Mesh"); DataTree <Polyline> PanelOutlines = DA.FetchTree <GH_Curve>("Panels").ToPolylineDT(); //Create joints DataTree <Vector3d> order = DA.FetchTree <GH_Vector>("InsertionVec").ToVectorDT(); //////////////////////////////////////////////////////////////////// // Insertion vectors //DataTree<Vector3d> EV = M.insertionVectors(Center, EVec); bool Center = DA.Fetch <bool>("Center"); if (order.DataCount == 0) { order = M.insertionVectorsJoints(Center, null);//joints } DataTree <Vector3d> EV = order; //////////////////////////////////////////////////////////////////// List <Point3d> twoJoints = DA.FetchList <Point3d>("TwoJoints"); List <Line> extendedJoints = DA.FetchList <Line>("ExtendedJoints"); List <Line> deeperCutsJoints = DA.FetchList <Line>("DeeperCutsJoints"); List <JointsVDAInputs> joints = GetJoints(order, M, twoJoints, extendedJoints, deeperCutsJoints); if (order.DataCount != 0) { order = M.insertionVectorsJoints(Center, joints);//joints } bool Finger = DA.Fetch <bool>("Finger"); DataTree <Polyline> CChamfer = new DataTree <Polyline>(); int iterations = DA.Fetch <int>("Iterations"); List <int> sequence = DA.FetchList <int>("Sequence"); List <double> textSize = DA.FetchList <double>("TextScale"); if (textSize.Count != 8) { textSize = new List <double> { 30, 12, 15, 0.5, 0.6, 0, 1, 5 } } ; DataTree <Panel> PanelGroups = DA.FetchTree <GH_Curve>("Panels").ToPanelsDT(); DataTree <Panel> JointGroups = new DataTree <Panel>(); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// int[][] tv = M.GetNGonsTopoBoundaries(); int[][] fe = M.GetNGonFacesEdges(tv); HashSet <int> e = M.GetAllNGonEdges(tv); Dictionary <int, int[]> efDict = M.GetFE(e, false); Point3d[] centers = M.GetNGonCenters(); Vector3d[] fn = M.GetNgonNormals(); //int[][] ef = M.GetNgonsConnectedToNGonsEdges(e, true); //////////////////////////////////////////////////////////////////// DataTree <Polyline> diagonalConnections = new DataTree <Polyline>(); //DataTree<Polyline> recJoints = new DataTree<Polyline>(); //Iterate insertion edges Dictionary <int, int> meshEdgeDict = new Dictionary <int, int>(); for (int i = 0; i < EV.BranchCount; i++) // EV.BranchCount { int meshEdge = EV.Path(i).Indices[0];//mesh edge is used as dataTree branch meshEdgeDict.Add(meshEdge, i); if (efDict[meshEdge].Length != 2) { continue; } int f0 = efDict[meshEdge][0]; int f1 = efDict[meshEdge][1]; //Divide line into points and create a planes on these point, following insertion direction and average face normal // Point3d[] pts = M.TopologyEdges.EdgeLine(meshEdge).InterpolateLine(divisions, false); Point3d[] pts = M.TopologyEdges.EdgeLine(meshEdge).InterpolateLine(joints[i].divisions, false); Vector3d avNormal = fn[f0] + fn[f1]; //Vector3d jointVector = Vector3d.CrossProduct(M.TopologyEdges.EdgeLine(meshEdge).Direction, avNormal); //EV.Branch(EV.Path(i))[0] = jointVector; for (int j = 0; j < pts.Length; j++) { //(new Line(pts[j], pts[j]+ avNormal*40)).Bake(); //JointGroups.Add(new Panel(new Plane(pts[j], EV.Branch(EV.Path(i))[0].UnitVector(), M.GetMeshEdgePerpDir(meshEdge))), EV.Path(i)); Plane plane = new Plane(pts[j], avNormal, EV.Branch(EV.Path(i))[0].UnitVector()); // Plane plane = new Plane(pts[j],EV.Branch(EV.Path(i))[0].UnitVector(), M.GetMeshEdgePerpDir(meshEdge)); plane = plane.Switch("YX"); JointGroups.Add(new Panel(plane), EV.Path(i)); //plane.Bake(40); } //Construct joint outlines from planes //Iterate number of joints per edge for (int j = 0; j < pts.Length; j++) { JointGroups.Branch(EV.Path(i))[j].planeOffset0 = JointGroups.Branch(EV.Path(i))[j].plane.MovePlanebyAxis(joints[i].thickness * 0.5); //offset planes JointGroups.Branch(EV.Path(i))[j].planeOffset1 = JointGroups.Branch(EV.Path(i))[j].plane.MovePlanebyAxis(-joints[i].thickness * 0.5); //offset planes JointGroups.Branch(EV.Path(i))[j].planeRot = new Plane(pts[j], Vector3d.CrossProduct(EV.Branch(EV.Path(i))[0].UnitVector(), M.GetMeshEdgePerpDir(meshEdge)), M.GetMeshEdgePerpDir(meshEdge)); int[] ngons = M.GetEdgeNgons(meshEdge); Plane tempPlane = JointGroups.Branch(EV.Path(i))[j].planeRot.MovePlanebyAxis(joints[i].length); int sign = tempPlane.Origin.DistanceToSquared(centers[ngons[0]]) < tempPlane.Origin.DistanceToSquared(centers[ngons[1]]) ? 1 : -1; JointGroups.Branch(EV.Path(i))[j].planeRotOffset0 = JointGroups.Branch(EV.Path(i))[j].planeRot.MovePlanebyAxis(joints[i].length * sign); //offset planes JointGroups.Branch(EV.Path(i))[j].planeRotOffset1 = JointGroups.Branch(EV.Path(i))[j].planeRot.MovePlanebyAxis(-joints[i].length * sign); //offset plane JointGroups.Branch(EV.Path(i))[j].planeEdge = new Plane(pts[j], M.TopologyEdges.EdgeLine(meshEdge).Direction, M.GetMeshEdgePerpDir(meshEdge)); List <Plane> planesF0 = new List <Plane>(); List <Plane> planesF1 = new List <Plane>(); for (int k = 0; k < PanelGroups.Branch(f0).Count; k++) { planesF0.Add(PanelGroups.Branch(f0)[k].plane); } for (int k = 0; k < PanelGroups.Branch(f1).Count; k++) { planesF1.Add(PanelGroups.Branch(f1)[k].plane); } JointGroups.Branch(EV.Path(i))[j].planeF0 = PlaneUtil.AveragePlaneOrigin(planesF0); JointGroups.Branch(EV.Path(i))[j].planeF1 = PlaneUtil.AveragePlaneOrigin(planesF1); //JointGroups.Branch(EV.Path(i))[j].planeF0.MovePlanebyAxis(joints[i].height).Bake(40); //JointGroups.Branch(EV.Path(i))[j].planeF1.MovePlanebyAxis(joints[i].height).Bake(40); List <Plane> jointPlaneLoop = new List <Plane> { JointGroups.Branch(EV.Path(i))[j].planeRotOffset0, JointGroups.Branch(EV.Path(i))[j].planeF0.MovePlanebyAxis(joints[i].height), JointGroups.Branch(EV.Path(i))[j].planeEdge, JointGroups.Branch(EV.Path(i))[j].planeF1.MovePlanebyAxis(joints[i].height), //3 JointGroups.Branch(EV.Path(i))[j].planeRotOffset1, JointGroups.Branch(EV.Path(i))[j].planeF1.MovePlanebyAxis(-joints[i].height), //5 JointGroups.Branch(EV.Path(i))[j].planeEdge, JointGroups.Branch(EV.Path(i))[j].planeF0.MovePlanebyAxis(-joints[i].height), }; //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(JointGroups.Branch(EV.Path(i))[j].planeF1, new Interval(-20, 20), new Interval(-20, 20))); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(JointGroups.Branch(EV.Path(i))[j].planeF1, new Interval(-20, 20), new Interval(-20, 20))); JointGroups.Branch(EV.Path(i))[j].contourNoJoints[0] = PolylineUtil.PolylineFromPlanes(JointGroups.Branch(EV.Path(i))[j].planeOffset0, jointPlaneLoop); JointGroups.Branch(EV.Path(i))[j].contourNoJoints[1] = PolylineUtil.PolylineFromPlanes(JointGroups.Branch(EV.Path(i))[j].planeOffset1, jointPlaneLoop); JointGroups.Branch(EV.Path(i))[j].contour[0] = new Polyline(JointGroups.Branch(EV.Path(i))[j].contourNoJoints[0]); JointGroups.Branch(EV.Path(i))[j].contour[1] = new Polyline(JointGroups.Branch(EV.Path(i))[j].contourNoJoints[1]); //JointGroups.Branch(EV.Path(i))[j].contour[0].Bake(); } //Construct Cuts //Iterate number of joints per edge for (int j = 0; j < pts.Length; j++) { int localMeshEdgeF0 = Array.IndexOf(fe[f0], meshEdge); int localMeshEdgeF1 = Array.IndexOf(fe[f1], meshEdge); //Iterate number of panels and create cuts for (int k = 0; k < PanelGroups.Branch(f0).Count; k++) { Panel jointPanel = JointGroups.Branch(EV.Path(i))[j]; //Rhino.RhinoApp.WriteLine(jointPanel.contourNoJoints[0].Count.ToString()); jointPanel.id = f0.ToString() + "-" + f1.ToString(); if (pts.Length > 1) { jointPanel.id += "-" + j.ToString(); } PanelGroups.Branch(f0)[k].CreateCut(localMeshEdgeF0, JointGroups.Branch(EV.Path(i))[j].planeOffset0, JointGroups.Branch(EV.Path(i))[j].planeOffset1, joints[i].length, ref jointPanel, false);//, ref neiPanel, ref jointPanel); //PanelGroups.Branch(f1)[k].CreateCut(localMeshEdgeF1, JointGroups.Branch(EV.Path(i))[j].planeOffset0, JointGroups.Branch(EV.Path(i))[j].planeOffset1, joints[i].length, ref jointPanel, false);//, ref neiPanel, ref jointPanel); JointGroups.Branch(EV.Path(i))[j] = jointPanel; } //Iterate number of panels and create cuts for (int k = 0; k < PanelGroups.Branch(f1).Count; k++) { Panel jointPanel = JointGroups.Branch(EV.Path(i))[j]; jointPanel.id = f0.ToString() + "-" + f1.ToString(); if (pts.Length > 1) { jointPanel.id += "-" + j.ToString(); } //PanelGroups.Branch(f0)[k].CreateCut(localMeshEdgeF0, JointGroups.Branch(EV.Path(i))[j].planeOffset0, JointGroups.Branch(EV.Path(i))[j].planeOffset1, joints[i].length, ref jointPanel, false);//, ref neiPanel, ref jointPanel); PanelGroups.Branch(f1)[k].CreateCut(localMeshEdgeF1, JointGroups.Branch(EV.Path(i))[j].planeOffset0, JointGroups.Branch(EV.Path(i))[j].planeOffset1, joints[i].length, ref jointPanel, false);//, ref neiPanel, ref jointPanel); JointGroups.Branch(EV.Path(i))[j] = jointPanel; } } } for (int i = 0; i < JointGroups.BranchCount; i++) { for (int j = 0; j < JointGroups.Branch(i).Count; j++) { if (joints[i].custom == 0) { if (joints[i].custom > 0) { JointGroups.Branch(i)[j].ChangeJoint(joints[i].custom, 0, joints[i].cutExtend, joints[i].addExtend); } else if (joints[i].custom < 0) { JointGroups.Branch(i)[j].ChangeJoint(joints[i].custom, 1, joints[i].cutExtend, joints[i].addExtend); } } } } ////////////////////////Output var dtPlates = new DataTree <Polyline>(); var dtJoints = new DataTree <Polyline>(); var dtPlatesMid = new DataTree <Polyline>(); var dtJointsMid = new DataTree <Polyline>(); var dtPlatesPlanes = new DataTree <Plane>(); var dtJointsPlanes = new DataTree <Plane>(); var dtPlatesTxt = new DataTree <Curve>(); var dtJointsTxt = new DataTree <Curve>(); var dtPlatesLast = new DataTree <Polyline>(); var dtJointsLast = new DataTree <Polyline>(); var dtPlatesMidLast = new DataTree <Polyline>(); var dtJointsMidLast = new DataTree <Polyline>(); var dtPlatesPlanesLast = new DataTree <Plane>(); var dtJointsPlanesLast = new DataTree <Plane>(); var dtPlatesTxtLast = new DataTree <Curve>(); var dtJointsTxtLast = new DataTree <Curve>(); HashSet <int> jointSequenceTemp = new HashSet <int>(); HashSet <int> jointSequence = new HashSet <int>(); HashSet <int> jointSequenceLast = new HashSet <int>(); int last = Math.Min(iterations, PanelGroups.BranchCount); int prev = Math.Max(0, last - (int)textSize[6]); for (int i = 0; i < last; i++) //Math.Min(iterations, sequence.Count) PanelGroups.BranchCount { for (int j = 0; j < fe[i].Length; j++) { bool seq = jointSequenceTemp.Add(fe[i][j]); if (i >= prev) { if (seq) { jointSequenceLast.Add(fe[i][j]); } else { jointSequence.Add(fe[i][j]); } } else { jointSequence.Add(fe[i][j]); } } for (int j = 0; j < PanelGroups.Branch(i).Count; j++) { if (i >= prev) { dtPlatesLast.Add(PanelGroups.Branch(i)[j].contour[0], new GH_Path(i, j)); dtPlatesLast.Add(PanelGroups.Branch(i)[j].contour[1], new GH_Path(i, j)); dtPlatesMidLast.Add(PanelGroups.Branch(i)[j].MidContour(), new GH_Path(i, j)); } else { dtPlates.Add(PanelGroups.Branch(i)[j].contour[0], new GH_Path(i, j)); dtPlates.Add(PanelGroups.Branch(i)[j].contour[1], new GH_Path(i, j)); dtPlatesMid.Add(PanelGroups.Branch(i)[j].MidContour(), new GH_Path(i, j)); } Plane textPlane = PanelGroups.Branch(i)[j].planeOffset0; textPlane.Flip(); if (j > 0) { textPlane = PanelGroups.Branch(i)[j].planeOffset1; } if (i >= prev) { dtPlatesPlanesLast.Add(textPlane, new GH_Path(i, j)); } else { dtPlatesPlanes.Add(textPlane, new GH_Path(i, j)); } string text = i.ToString() + "-" + j.ToString(); var txtCrv = Typewriter.Regular.Write(text, textPlane, textSize[0]); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrv, new GH_Path(i, j)); } else { dtPlatesTxt.AddRange(txtCrv, new GH_Path(i, j)); } var a = PanelGroups.Branch(i)[j]; Line[] segments = PanelGroups.Branch(i)[j].contourNoJoints[Math.Min(1, j)].GetSegments(); int counter = 0; foreach (Line l in segments) { int meshEdge = fe[i][counter]; int neiF = M.GetOppositeNgon(meshEdge, i); //Adjacent face plane Point3d origin = l.PointAt(textSize[3]); Vector3d xaxis = l.Direction; Vector3d yaxis = l.Direction; origin.Transform(Rhino.Geometry.Transform.Scale(textPlane.Origin, textSize[4])); yaxis.Rotate(Math.PI * 0.5, textPlane.ZAxis); Plane ePlane = new Plane(origin, xaxis, yaxis); var txtCrvF = Typewriter.Regular.Write(neiF.ToString(), ePlane, textSize[2]); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrvF, new GH_Path(i, j)); } else { dtPlatesTxt.AddRange(txtCrvF, new GH_Path(i, j)); } //Mesh edge direction Line meshEdgeLine = M.TopologyEdges.EdgeLine(meshEdge); meshEdgeLine.Transform(Rhino.Geometry.Transform.Scale(meshEdgeLine.PointAt(0.5), textSize[4])); meshEdgeLine.Transform(Rhino.Geometry.Transform.Scale(textPlane.Origin, textSize[4])); //meshEdgeLine.Extend(-textSize[4], -textSize[4]); Plane e0Plane = new Plane(ePlane.ClosestPoint(meshEdgeLine.From), xaxis, yaxis); Plane e1Plane = new Plane(ePlane.ClosestPoint(meshEdgeLine.To), xaxis, yaxis); var txtCrvF0 = Typewriter.Regular.Write("I", e0Plane, textSize[2]); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrvF0, new GH_Path(i, j)); } else { dtPlatesTxt.AddRange(txtCrvF0, new GH_Path(i, j)); } var txtCrvF1 = Typewriter.Regular.Write("II", e1Plane, textSize[2]); if (i >= prev) { dtPlatesTxtLast.AddRange(txtCrvF1, new GH_Path(i, j)); } else { dtPlatesTxt.AddRange(txtCrvF1, new GH_Path(i, j)); } counter++; // } } } DataTree <Vector3d> insertionVectors = new DataTree <Vector3d>(); foreach (int meshEdge in jointSequence) { if (!meshEdgeDict.ContainsKey(meshEdge)) { continue; } int i = meshEdgeDict[meshEdge]; for (int j = 0; j < JointGroups.Branch(i).Count; j++) { GH_Path path = new GH_Path(meshEdge, j); insertionVectors.Add(JointGroups.Branch(i)[j].planeOffset0.XAxis, path); dtJoints.Add(JointGroups.Branch(i)[j].contour[0], path); dtJoints.Add(JointGroups.Branch(i)[j].contour[1], path); dtJointsMid.Add(JointGroups.Branch(i)[j].MidContour(), path); dtJointsPlanes.Add(JointGroups.Branch(i)[j].planeOffset0, path); Plane planet = new Plane(JointGroups.Branch(i)[j].planeOffset0.Origin + JointGroups.Branch(i)[j].planeOffset0.YAxis * textSize[5], JointGroups.Branch(i)[j].planeOffset0.XAxis, JointGroups.Branch(i)[j].planeOffset0.YAxis); string text = JointGroups.Branch(i)[j].id; var txtCrv = Typewriter.Regular.Write(text, planet, textSize[1]); dtJointsTxt.AddRange(txtCrv, path); } } foreach (int meshEdge in jointSequenceLast) { if (!meshEdgeDict.ContainsKey(meshEdge)) { continue; } int i = meshEdgeDict[meshEdge]; for (int j = 0; j < JointGroups.Branch(i).Count; j++) { dtJointsLast.Add(JointGroups.Branch(i)[j].contour[0], new GH_Path(meshEdge, j)); dtJointsLast.Add(JointGroups.Branch(i)[j].contour[1], new GH_Path(meshEdge, j)); dtJointsMidLast.Add(JointGroups.Branch(i)[j].MidContour(), new GH_Path(meshEdge, j)); dtJointsPlanesLast.Add(JointGroups.Branch(i)[j].planeOffset0, new GH_Path(meshEdge, j)); Plane planet = new Plane(JointGroups.Branch(i)[j].planeOffset0.Origin + JointGroups.Branch(i)[j].planeOffset0.YAxis * textSize[5], JointGroups.Branch(i)[j].planeOffset0.XAxis, JointGroups.Branch(i)[j].planeOffset0.YAxis); string text = JointGroups.Branch(i)[j].id; var txtCrv = Typewriter.Regular.Write(text, planet, textSize[1]); dtJointsTxtLast.AddRange(txtCrv, new GH_Path(meshEdge, j)); } } DA.SetDataTree(0, dtPlates); DA.SetDataTree(1, dtJoints); DA.SetDataTree(2, dtPlatesMid); DA.SetDataTree(3, dtJointsMid); DA.SetDataTree(4, dtPlatesPlanes); DA.SetDataTree(5, dtJointsPlanes); DA.SetDataTree(6, dtPlatesTxt); DA.SetDataTree(7, dtJointsTxt); DA.SetDataTree(8, dtPlatesLast); DA.SetDataTree(9, dtJointsLast); DA.SetDataTree(10, dtPlatesMidLast); DA.SetDataTree(11, dtJointsMidLast); DA.SetDataTree(12, dtPlatesPlanesLast); DA.SetDataTree(13, dtJointsPlanesLast); DA.SetDataTree(14, dtPlatesTxtLast); DA.SetDataTree(15, dtJointsTxtLast); } catch (Exception e) { Rhino.RhinoApp.WriteLine(e.ToString()); } }
//Main Methods public DataTree <Polyline> Beams2(NGonsCore.MeshProps p) { DataTree <Polyline> dt = new DataTree <Polyline>(); try { //Edge and End Planes Dictionary <int, int> E = p.M._EAll();//mesh edge - ngon edge for (int i = 0; i < p.M._countF(); i++) { int[] fe = p.M._fe(i); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0) { int e = E[fe[j]];//get ngon Edge by local meshedge this[i, j].ePl90 = p.ePl90[e].ChangeOrigin(this[i, j].line.Center()); this[i, j].ePl = p.ePl[e].ChangeOrigin(this[i, j].line.Center()); this[i, j].ePl90Offset = this[i, j].ePl90.MovePlanebyAxis(depth); int[] o = p.M._OppositeFE(i, j); int i_ = (o[0] != -1) ? o[0] : i; int j_ = (o[1] != -1) ? o[1] : j; int naked = (o[0] != -1) ? 1 : -1; Plane ePl0 = this[i, j].ePl; Plane ePl1 = new Plane(this[i, j].ePl.Origin, this[i, j].ePl.YAxis, this[i, j].ePl.ZAxis); Plane cPl = p.fPl[i]; Plane oPl = p.fPl[i_]; Point3d originC = PlaneUtil.PlanePlanePlane(ePl0, ePl1, cPl); Point3d originO = PlaneUtil.PlanePlanePlane(ePl0, ePl1, oPl); //Plane correspoding to current face plane Plane fcPl = p.fePl[i][j].ChangeOrigin(originC); Plane fcPl90 = p.fePl90[i][j].ChangeOrigin(originC); Vector3d v0 = -fcPl.ZAxis * offset0 * scale; Vector3d v1 = -fcPl.YAxis * plateThickness; Plane fcPl0 = fcPl90; //this[i, j].fcPl.Add(fcPl90); this[i, j].fcPl.Add(fcPl.Translation(v0 * extend)); this[i, j].fcPl.Add(fcPl90.Translation(v0 + v1)); this[i, j].fcPl.Add(this[i, j].ePl.Translation(v0 * 2)); if (i == 10) { //Line line = new Line(originO.zy); //this[i, j].fcPl.Bake(); } //Plane corresponding to opposite plane Plane foPl = p.fePl[i_][j_].ChangeOrigin(originO); Plane foPl90 = p.fePl90[i_][j_].ChangeOrigin(originO); v0 = -foPl.ZAxis * offset0 * scale * naked;//for naked opposite - do i need to flip? v1 = -foPl.YAxis * plateThickness; this[i, j].foPl.Add(this[i, j].ePl.Translation(v0 * 2)); this[i, j].foPl.Add(foPl90.Translation(v0 + v1)); this[i, j].foPl.Add(foPl.Translation(v0 * extend)); //this[i, j].foPl.Add(foPl90); Plane foPl3 = foPl90; //Average plane for chamfer middle part of the beam Line l1 = PlaneUtil.PlanePlane(fcPl90, this[i, j].fcPl[0]); Line l0 = PlaneUtil.PlanePlane(this[i, j].foPl[2], foPl90); this[i, j].fcPl_foPl = new Plane((l0.Center() + l1.Center()) * 0.5, l0.Direction, l0.Center() - l1.Center()); //End Planes - next edge opposite int ne = E[fe.Next(j)]; //get next ngon edge int[] no = p.M._OppositeFE(i, (j + 1).Wrap(p.M._countE(i))); //get next opposite edge this[i, j].endPl0 = (no[0] != -1) ? this[i, j].endPl0 = p.ePl[ne].ChangeOrigin(this[no[0], no[1]].line.Center()) : this[i, j].endPl0 = p.ePl[ne].ChangeOrigin(this[i, j].line.To); //change origin because planes are located at mesh edge this[i, j].endPl0 = this[i, j].endPl0.MovePlanebyAxis(offset0 * 2, this[i, j].line.Center()); //move towards the center //End Planes - prev edge opposite int pe = E[fe.Prev(j)]; //get previous ngon edge int[] po = p.M._OppositeFE(i, (j - 1).Wrap(p.M._countE(i))); ////get prev opposite edge this[i, j].endPl1 = (po[0] != -1) ? p.ePl[pe].ChangeOrigin(this[po[0], po[1]].line.Center()) : p.ePl[pe].ChangeOrigin(this[i, j].line.From); //change origin because planes are located at mesh edge this[i, j].endPl1 = this[i, j].endPl1.MovePlanebyAxis(offset0 * 2, this[i, j].line.Center()); //move towards the center }//is nexor }//for j }//for i //Nodes profiles for (int i = 0; i < p.M._countF(); i++) { int[] fe = p.M._fe(i); for (int j = 0; j < p.M._countE(i); j++) { if (this[i, j].isNexor != 0) { List <Polyline> cutters0 = new List <Polyline>(); List <Plane> sidePlanes = new List <Plane>(); sidePlanes.AddRange(this[i, j].fcPl); sidePlanes.Add(this[i, j].ePl90Offset); sidePlanes.AddRange(this[i, j].foPl); sidePlanes.Add(this[i, j].fcPl_foPl); if ((!p.M.IsNaked(fe[j])))// { //End Planes - next edge opposite int[] op = p.M._OppositeFE(i, j, -1); int[] on = p.M._OppositeFE(i, j, 1); int[] no = p.M._OppositeFE(i, (j + 1).Wrap(fe.Length)); //for end parts int[] po = p.M._OppositeFE(i, (j - 1).Wrap(fe.Length)); //for end parts //First profile Polyline p0 = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0, sidePlanes); //Plane sectionPlaneP0 = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].ePl : this[op[0], op[1]].fcPl[0]; if (op[0] != -1) { p0 = PolylineUtil.PolylineFromPlanes(this[op[0], op[1]].fcPl[0], sidePlanes); } List <Plane> sidePlanes1A = new List <Plane>(); sidePlanes1A.AddRange(this[i, j].fcPl); sidePlanes1A.Add(this[i, j].ePl90Offset); sidePlanes1A.Add(this[i, j].foPl[0]); sidePlanes1A.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes1A.Add(this[i, j].fcPl_foPl); Plane sectionPlaneP3A_ = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].foPl[0] : this[op[0], op[1]].foPl[0]; Plane sectionPlaneP3A = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].fcPl[2] : this[op[0], op[1]].foPl[0]; if (p.M.IsNaked(fe.Next(j)) && (p.M.TopologyEdges.EdgeLine(fe.Next(j)).To.Z < z || p.M.TopologyEdges.EdgeLine(fe.Next(j)).From.Z < z)) { sectionPlaneP3A_ = ground; this[i, j].endPl0 = ground; } List <Plane> sidePlanes1BExtended = new List <Plane>(); sidePlanes1BExtended.Add(this[i, j].fcPl[0]); sidePlanes1BExtended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true)); sidePlanes1BExtended.Add(this[i, j].foPl[0]); sidePlanes1BExtended.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes1BExtended.Add(this[i, j].fcPl_foPl); Polyline p2A = PolylineUtil.PolylineFromPlanes(this[op[0], op[1]].fcPl[0], sidePlanes1A); Polyline p3A = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A, sidePlanes1A);//Top Removal - Inner Polyline p3A_ = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A_, sidePlanes1A); Polyline p3A_Extended = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A, sidePlanes1BExtended); //1 cutters0.Add(p3A_Extended); this[i, j].profiles.Add(p2A); this[i, j].profiles.Add(p3A_); if (p.M.IsNaked(fe.Next(j))) { this[i, j].endPl0 = sectionPlaneP3A_; } if (no[0] != -1)//i == 20 && j == 1 && { List <Plane> sidePlanes2 = new List <Plane>(); sidePlanes2.AddRange(this[i, j].fcPl); sidePlanes2.Add(this[i, j].ePl90Offset); sidePlanes2.Add(this[i, j].foPl[0]); sidePlanes2.Add(this[no[0], no[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2.Add(this[i, j].fcPl_foPl); List <Plane> sidePlanes2Extended = new List <Plane>(); sidePlanes2Extended.Add(this[i, j].fcPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true)); sidePlanes2Extended.Add(this[i, j].foPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[no[0], no[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2Extended.Add(this[i, j].fcPl_foPl); Polyline p4A = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0, sidePlanes2); //Top Removal - End Polyline p4A_Extended = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0.MovePlanebyAxis(0.00, this[i, j].line.Center(), 2, false), sidePlanes2Extended); //Top Removal - End - 0 cutters0.Insert(0, p4A_Extended); this[i, j].profiles.Add(p3A); this[i, j].profiles.Add(p4A); } //Second profile Polyline p1 = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1, sidePlanes); //Plane sectionPlaneP1 = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].ePl : this[on[0], on[1]].fcPl[0]; if (on[0] != -1) { p1 = PolylineUtil.PolylineFromPlanes(this[on[0], on[1]].fcPl[0], sidePlanes); } List <Plane> sidePlanes1B = new List <Plane>(); sidePlanes1B.AddRange(this[i, j].fcPl); sidePlanes1B.Add(this[i, j].ePl90Offset); sidePlanes1B.Add(this[i, j].foPl[0]); sidePlanes1B.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes1B.Add(this[i, j].fcPl_foPl); Plane sectionPlaneP3B_ = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].foPl[0] : this[on[0], on[1]].foPl[0]; Plane sectionPlaneP3B = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].fcPl[2] : this[on[0], on[1]].foPl[0]; if (p.M.IsNaked(fe.Prev(j)) && (p.M.TopologyEdges.EdgeLine(fe.Prev(j)).To.Z < z || p.M.TopologyEdges.EdgeLine(fe.Prev(j)).From.Z < z)) { sectionPlaneP3B_ = ground; this[i, j].endPl1 = ground; //p.M.TopologyEdges.EdgeLine(fe[j]).Center().Bake(); } Polyline p2B = PolylineUtil.PolylineFromPlanes(this[on[0], on[1]].fcPl[0], sidePlanes1B); Polyline p3B = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B, sidePlanes1B);//Top Removal - Inner Polyline p3B_ = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B_, sidePlanes1B); Polyline p3B_Extended = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B, sidePlanes1BExtended);//Top Removal - Inner2 cutters0.Add(p3B_Extended); this[i, j].profiles.Add(p2B); this[i, j].profiles.Add(p3B_); if (p.M.IsNaked(fe.Prev(j))) { this[i, j].endPl1 = sectionPlaneP3B_; } if (po[0] != -1)//i == 20 && j == 1 && { List <Plane> sidePlanes2 = new List <Plane>(); sidePlanes2.AddRange(this[i, j].fcPl); sidePlanes2.Add(this[i, j].ePl90Offset); sidePlanes2.Add(this[i, j].foPl[0]); sidePlanes2.Add(this[po[0], po[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2.Add(this[i, j].fcPl_foPl); List <Plane> sidePlanes2Extended = new List <Plane>(); sidePlanes2Extended.Add(this[i, j].fcPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true)); sidePlanes2Extended.Add(this[i, j].foPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false)); sidePlanes2Extended.Add(this[po[0], po[1]].foPl[1].MovePlanebyAxis(plateThickness)); sidePlanes2Extended.Add(this[i, j].fcPl_foPl); Polyline p4B = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1, sidePlanes2); //Top Removal - End Polyline p4B_Extended = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1.MovePlanebyAxis(0.00, this[i, j].line.Center(), 2, false), sidePlanes2Extended); //Top Removal - End //3 cutters0.Add(p4B_Extended); //p4B_Extended.Bake(); //p2.Bake(); //p3.Bake(); //p4.Bake(); this[i, j].profiles.Add(p4B); this[i, j].profiles.Add(p3B); } this[i, j].profiles.Add(p0); this[i, j].profiles.Add(p1); //End profile } else if (this[i, j].isNexor == 1) { List <Plane> sidePlanesNaked = new List <Plane>(); sidePlanesNaked.AddRange(this[i, j].fcPl); sidePlanesNaked.Add(this[i, j].ePl90Offset); sidePlanesNaked.Add(this[i, j].foPl[0]); sidePlanesNaked.Add(this[i, j].fcPl_foPl); Plane planeA = (this[i, j].endPl0.Origin.Z < z) ? ground : this[i, j].endPl0; Plane planeB = (this[i, j].endPl1.Origin.Z < z) ? ground : this[i, j].endPl1; if (this[i, j].endPl0.Origin.Z < z) { this[i, j].endPl0 = ground; } if (this[i, j].endPl1.Origin.Z < z) { this[i, j].endPl1 = ground; } Polyline p0 = PolylineUtil.PolylineFromPlanes(planeA, sidePlanesNaked); Polyline p1 = PolylineUtil.PolylineFromPlanes(planeB, sidePlanesNaked); this[i, j].profiles.Add(p0); this[i, j].profiles.Add(p1); } else if (this[i, j].isNexor == -1) { List <Plane> sidePlanesNaked = new List <Plane>(); sidePlanesNaked.Add(this[i, j].ePl90Offset); sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[2]); sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[1]); sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[0]); sidePlanesNaked.Add(this[i, j].fcPl_foPl); sidePlanesNaked.AddRange(this[i, (j - 1).Wrap(fe.Length)].fcPl); this[i, j].endPl0 = this[i, (j + 1).Wrap(fe.Length)].fcPl[0]; this[i, j].endPl1 = this[i, (j - 1).Wrap(fe.Length)].fcPl[0]; Polyline p0 = PolylineUtil.PolylineFromPlanes(this[i, j].fcPl[0], sidePlanesNaked); Polyline p1 = PolylineUtil.PolylineFromPlanes(this[i, j].foPl[0], sidePlanesNaked); //p0.Bake(); //p1.Bake(); this[i, j].profiles.Add(p0); this[i, j].profiles.Add(p1); //p0.Bake(); //p1.Bake(); } this[i, j].CNC_Cuts.AddRange(cutters0, new Grasshopper.Kernel.Data.GH_Path(i, j)); } } } foreach (var n in this._nexors) { if (n.isNexor != 0) { var path = new Grasshopper.Kernel.Data.GH_Path(n.idNested[0], n.idNested[1]); if (n.profiles.Count > 0) { dt.AddRange(n.profiles, path); } } } } catch (Exception e) { Rhino.RhinoApp.WriteLine(e.ToString()); } return(dt); }
public DataTree <Polyline> Cuts() { DataTree <Polyline> dt = new DataTree <Polyline>(); //Create end cuts for (int i = 0; i < this._nexors.Count; i++) { if (this._nexors[i].isNexor != 0) { var path = new Grasshopper.Kernel.Data.GH_Path(this.id_[i].Item1, this.id_[i].Item2); //1. Get bisector planes List <Plane> sidePlanes = new List <Plane>() { this._nexors[i].fcPl[2], this._nexors[i].endPl0, this._nexors[i].foPl[0], this._nexors[i].endPl1 }; Polyline outline = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset, sidePlanes); Plane[] bisectors = outline.PolylineBisectors(); Plane higherPlane = (this._nexors[i].fcPl[1].Origin.DistanceToSquared(this._nexors[i].ePl90Offset.Origin) > this._nexors[i].foPl[1].Origin.DistanceToSquared(this._nexors[i].ePl90Offset.Origin)) ? this._nexors[i].fcPl[1] : this._nexors[i].foPl[1]; higherPlane = higherPlane.MovePlanebyAxis(this.plateThickness * 3); Plane lowerPlane = this._nexors[i].ePl90Offset.MovePlanebyAxis(-this.plateThickness * 3); Polyline outline1 = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes); Plane[] bisectors1 = outline1.PolylineBisectors(); for (int j = 0; j < bisectors.Length; j++) { bisectors[j] = new Plane( (bisectors[j].Origin + bisectors1[j].Origin) * 0.5, (bisectors[j].XAxis + bisectors1[j].XAxis) * 0.5, bisectors[j].Origin - bisectors1[j].Origin ); } //Create V-Shape cuts Point3d nexorCenter = this._nexors[i].line.Center(); sidePlanes = new List <Plane>() { this._nexors[i].endPl0.MovePlanebyAxis(0.2, nexorCenter), this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, nexorCenter, 2, false), bisectors[0], this._nexors[i].endPl0, bisectors[1], this._nexors[i].foPl[0].MovePlanebyAxis(0.1, nexorCenter, 2, false) , }; Polyline endCuts0A = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true); Polyline endCuts0B = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true); sidePlanes[0] = sidePlanes[0].MovePlanebyAxis(-0.2 * 2, nexorCenter, 2, false); Polyline endCuts0A_ = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true); Polyline endCuts0B_ = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true); //endCuts0A_.Bake(); //endCuts0B_.Bake(); sidePlanes = new List <Plane>() { this._nexors[i].endPl1.MovePlanebyAxis(0.2, nexorCenter), this._nexors[i].foPl[0].MovePlanebyAxis(0.1, nexorCenter, 2, false), bisectors[2], this._nexors[i].endPl1, bisectors[3], this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, nexorCenter, 2, false) }; Polyline endCuts1A = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true); Polyline endCuts1B = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true); sidePlanes[0] = sidePlanes[0].MovePlanebyAxis(-0.2 * 2, nexorCenter, 2, false); Polyline endCuts1A_ = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true); Polyline endCuts1B_ = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true); //endCuts1A_.Bake(); //endCuts1B_.Bake(); this._nexors[i].CNCendBladeSawCuts0.Add(endCuts0A_); this._nexors[i].CNCendBladeSawCuts0.Add(endCuts0B_); this._nexors[i].CNCendBladeSawCuts1.Add(endCuts1A_); this._nexors[i].CNCendBladeSawCuts1.Add(endCuts1B_); this._nexors[i].CNCendBladeSawCuts0Negative.Add(endCuts0A); this._nexors[i].CNCendBladeSawCuts0Negative.Add(endCuts0B); this._nexors[i].CNCendBladeSawCuts1Negative.Add(endCuts1A); this._nexors[i].CNCendBladeSawCuts1Negative.Add(endCuts1B); dt.AddRange(this._nexors[i].CNCendBladeSawCuts0, path); dt.AddRange(this._nexors[i].CNCendBladeSawCuts1, path); //if (this._nexors[i].isNexor == -1) //{ // endCuts0A.Bake(); // endCuts0B.Bake(); // endCuts1A.Bake(); // endCuts1B.Bake(); //} } } //Collect neighbour cuts for (int i = 0; i < this._nexors.Count; i++) { var path = new Grasshopper.Kernel.Data.GH_Path(this.id_[i].Item1, this.id_[i].Item2); int[] adjE0S = this._nexors[i].adjE0S; int[] adjE1S = this._nexors[i].adjE1S; if (this._nexors[i].isNexor == 1) { if (adjE0S[0] != -1) { dt.AddRange(this[adjE0S[0], adjE0S[1]].CNCendBladeSawCuts0Negative, path); } if (adjE1S[0] != -1) { dt.AddRange(this[adjE1S[0], adjE1S[1]].CNCendBladeSawCuts1Negative, path); } //Bottom cut Point3d c = this._nexors[i].line.Center(); List <Plane> sidePlanes = new List <Plane>() { this._nexors[i].endPl0.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, c, 2, false), this._nexors[i].endPl1.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].foPl[0].MovePlanebyAxis(0.1, c, 2, false) }; Polyline bottomCut0 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset, sidePlanes); Polyline bottomCut1 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset.MovePlanebyAxis(0.1, c, 2, false), sidePlanes); //dt.Add(bottomCut0,path); //dt.Add(bottomCut1, path); dt.AddRange(this._nexors[i].CNCtopProfileCuts, path); //bottomCut0.Bake(); //bottomCut1.Bake(); } if (this._nexors[i].isNexor == -1) { dt.AddRange(this._nexors[i].CNCendBladeSawCuts0Negative, new Grasshopper.Kernel.Data.GH_Path(adjE0S[0], adjE0S[1])); dt.AddRange(this._nexors[i].CNCendBladeSawCuts1Negative, new Grasshopper.Kernel.Data.GH_Path(adjE1S[0], adjE1S[1])); //Bottom cut Point3d c = this._nexors[i].line.Center(); List <Plane> sidePlanes = new List <Plane>() { this._nexors[i].endPl0.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, c, 2, false), this._nexors[i].endPl1.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].foPl[0].MovePlanebyAxis(0.1, c, 2, false) }; Polyline bottomCut0 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset, sidePlanes); Polyline bottomCut1 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset.MovePlanebyAxis(0.1, c, 2, false), sidePlanes); //dt.Add(bottomCut0, path); //dt.Add(bottomCut1, path); dt.AddRange(this._nexors[i].CNCtopProfileCuts, path); //instead of path ????????????????????? //Rhino.RhinoApp.WriteLine(String.Format("adj {0} - {1}, {2}-{3} , {4}-{5}", // adjE0S[0], // adjE0S[1], // adjE1S[0], // adjE1S[1], // this._nexors[i].idNested [0], // this._nexors[i].idNested[1] // )); //Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(this._nexors[i].pipe.breploft); } } for (int i = 0; i < this._nexors.Count; i++) { if (this._nexors[i].isNexor != 0) { var path = new Grasshopper.Kernel.Data.GH_Path(this.id_[i].Item1, this.id_[i].Item2); Point3d c = this._nexors[i].pipe.line.Center(); List <Plane> sidePlanes = new List <Plane>() { this._nexors[i].fcPl[0].MovePlanebyAxis(0.01, c, 2, false), this._nexors[i].endPl0.MovePlanebyAxis(0.01, c, 2, false), this._nexors[i].foPl[2].MovePlanebyAxis(0.01, c, 2, false), this._nexors[i].endPl1.MovePlanebyAxis(0.01, c, 2, false), }; Polyline angledCut0 = PolylineUtil.PolylineFromPlanes(this._nexors[i].fcPl_foPl, sidePlanes); Polyline angledCut1 = PolylineUtil.PolylineFromPlanes(this._nexors[i].fcPl_foPl.MovePlanebyAxis(0.1, c, 2, false), sidePlanes); //dt.Add(angledCut0, path); //dt.Add(angledCut1, path); //bottomCut0.Bake(); //bottomCut1.Bake(); } } return(dt); }
public Polyline[][] GetSupportStructure(Mesh M, double W1, double W2, Plane[] facePlanes, Plane[] linePlanes, Plane[][] endPlanes, int[][] fe_, int[][] fe, Surface s, Dictionary <int, int> eDict, ref Plane[] ep0, ref Plane[] ep1, ref Plane[] lp2, ref Plane[] lp3) { //double thickness = 1.2; //double heightScale = 2; double thickness = W1; double heightScale = W2 * 2; double extend = 1; bool flip = true; Polyline[][] support = new Polyline[linePlanes.Length][]; ep0 = new Plane[linePlanes.Length]; //Neighbour planes0 ep1 = new Plane[linePlanes.Length]; //Neighbour planes01 Plane[] lp0 = new Plane[linePlanes.Length]; //line planes0 Plane[] lp1 = new Plane[linePlanes.Length]; //line planes1 lp2 = new Plane[linePlanes.Length]; //line planes2 rotated 90 lp3 = new Plane[linePlanes.Length]; //line planes3 rotated 90 for (int i = 0; i < linePlanes.Length; i++) { Line projectionAxis = new Line(linePlanes[i].Origin, linePlanes[i].Origin + linePlanes[i].YAxis); Point3d projectedPt = NGonsCore.MeshUtilSimple.SurfaceRay(s, projectionAxis); //Six sides of each beam lp0[i] = linePlanes[i].MovePlanebyAxis(thickness); lp1[i] = linePlanes[i].MovePlanebyAxis(-thickness); lp2[i] = (new Plane(projectedPt, linePlanes[i].XAxis, linePlanes[i].ZAxis)).MovePlanebyAxis(heightScale); lp3[i] = (new Plane(projectedPt, linePlanes[i].XAxis, linePlanes[i].ZAxis)).MovePlanebyAxis(0); ep0[i] = endPlanes[i][0].MovePlanebyAxis(thickness, linePlanes[i].Origin, 2, flip); ep1[i] = endPlanes[i][1].MovePlanebyAxis(thickness, linePlanes[i].Origin, 2, flip); Plane endPlane0_Offset = endPlanes[i][0].MovePlanebyAxis(thickness * extend, linePlanes[i].Origin, 2, !flip); Plane endPlane1_Offset = endPlanes[i][1].MovePlanebyAxis(thickness * extend, linePlanes[i].Origin, 2, !flip); //Rectangle3d r0 = new Rectangle3d(lp2[i],10,10); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(r0); //First outlines List <Plane> sidePlanes = new List <Plane>() { lp0[i], lp2[i], lp1[i], lp3[i] }; Polyline topOutline = PolylineUtil.PolylineFromPlanes(ep0[i], sidePlanes); Polyline botOutline = PolylineUtil.PolylineFromPlanes(ep1[i], sidePlanes); ep0[i] = new Plane(topOutline.CenterPoint(), topOutline.SegmentAt(0).Direction, topOutline.SegmentAt(1).Direction); ep1[i] = new Plane(botOutline.CenterPoint(), botOutline.SegmentAt(0).Direction, botOutline.SegmentAt(1).Direction); Point3d center = (ep0[i].Origin + ep1[i].Origin) * 0.5; if (center.DistanceToSquared(ep0[i].Origin + ep0[i].ZAxis) < center.DistanceToSquared(ep0[i].Origin)) { ep0[i].Flip(); ep0[i].Rotate(-Math.PI * 0.5, ep0[i].ZAxis); } if (center.DistanceToSquared(ep1[i].Origin + ep1[i].ZAxis) < center.DistanceToSquared(ep1[i].Origin)) { ep1[i].Flip(); ep1[i].Rotate(-Math.PI * 0.5, ep1[i].ZAxis); } // ///if (i == 0) // Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(ep0[i],10,10)); support[i] = new Polyline[] { topOutline, botOutline }; } //Loop each edge Tuple <int, int>[][] efe = M.GetEF_LocalID(M.GetAllNGonEdges(M.GetNGonsTopoBoundaries())); for (int i = 0; i < linePlanes.Length; i++) { //int meshE = eDict[i]; Tuple <int, int>[] edgeFaces = efe[i]; //if edge has two faces go inside their local edges if (edgeFaces.Length == 2) { int e0 = fe_[edgeFaces[0].Item1].Next(edgeFaces[0].Item2); int e1 = fe_[edgeFaces[0].Item1].Prev(edgeFaces[0].Item2); int e2 = fe_[edgeFaces[1].Item1].Next(edgeFaces[1].Item2); int e3 = fe_[edgeFaces[1].Item1].Prev(edgeFaces[1].Item2); if (i == 11) { Line[] lines = PolylineUtil.LoftLine(support[i][0], support[i][1]); Point3d[] pInt = PlaneUtil.LinePlane(lines, linePlanes[e0]); Rectangle3d rec = new Rectangle3d(linePlanes[i], 20, 20); Rectangle3d rec0 = new Rectangle3d(linePlanes[e0], 10, 10); Rectangle3d rec1 = new Rectangle3d(linePlanes[e2], 10, 10); //rec.pl //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec1); //Current stick intersection //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e0])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e1])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e2])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e3])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e0])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e1])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e2])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e3])); //Compare with neighbour stick intersection - the 4 points } } } return(support); }
public Polyline[][] FaceOutlines(Mesh M, Plane[] facePlanes, Plane[] linePlanes, int[][] fe_, int[][] fe, double offset, double thickness, Line[] cutLines, Dictionary <int, int> e, Surface rs) { Mesh projectionMesh = Mesh.CreateFromBrep(rs.ToBrep())[0]; Polyline[][] outlines = new Polyline[facePlanes.Length][]; Polyline[][] outlinesCopy = new Polyline[facePlanes.Length][]; //Draw perpendicular joint Tuple <int, int>[][] efe = M.GetEF_LocalID(M.GetAllNGonEdges(M.GetNGonsTopoBoundaries())); if (offset > 0) { for (int i = 0; i < facePlanes.Length; i++) { //Base Planes Plane basePlane0 = new Plane(facePlanes[i].MovePlanebyAxis(offset * 0.5 + thickness * 0.5)); Plane basePlane1 = new Plane(facePlanes[i].MovePlanebyAxis(offset * 0.5 + -thickness * 0.5)); Plane basePlane2 = new Plane(facePlanes[i].MovePlanebyAxis(offset * -0.5 + thickness * 0.5)); Plane basePlane3 = new Plane(facePlanes[i].MovePlanebyAxis(offset * -0.5 + -thickness * 0.5)); //Side Planes List <Plane> sidePlanes = new List <Plane>(); for (int j = 0; j < fe_[i].Length; j++) { sidePlanes.Add(linePlanes[fe_[i][MathUtil.Wrap(j - 1, fe_[i].Length)]]); } //Intersect base plane with side planes Polyline outline0 = PolylineUtil.PolylineFromPlanes(basePlane0, sidePlanes); Polyline outline1 = PolylineUtil.PolylineFromPlanes(basePlane1, sidePlanes); Polyline outline2 = PolylineUtil.PolylineFromPlanes(basePlane2, sidePlanes); Polyline outline3 = PolylineUtil.PolylineFromPlanes(basePlane3, sidePlanes); outlines[i] = new Polyline[] { outline0, outline1, outline2, outline3 }; } return(outlines); } else { List <Plane>[] sidePlanes = new List <Plane> [facePlanes.Length]; for (int i = 0; i < facePlanes.Length; i++) { //Base Planes Plane basePlane0 = new Plane(facePlanes[i].MovePlanebyAxis(thickness * 0.5)); Plane basePlane1 = new Plane(facePlanes[i].MovePlanebyAxis(-thickness * 0.5)); //Side Planes sidePlanes[i] = new List <Plane>(); for (int j = 0; j < fe_[i].Length; j++) { sidePlanes[i].Add(linePlanes[fe_[i][j]]); } //Intersect base plane with side planes Polyline outline0 = PolylineUtil.PolylineFromPlanes(basePlane0, sidePlanes[i]); Polyline outline1 = PolylineUtil.PolylineFromPlanes(basePlane1, sidePlanes[i]); Polyline outline0Copy = new Polyline(outline0); Polyline outline1Copy = new Polyline(outline1); outlines[i] = new Polyline[] { outline0, outline1 }; outlinesCopy[i] = new Polyline[] { new Polyline(outline0), new Polyline(outline1) }; }//for i for (int i = 0; i < facePlanes.Length; i++) { //Loop segments and check intersection for (int j = 0; j < outlines[i][0].Count - 1; j++) { //Get current segment Line segment0 = outlines[i][0].SegmentAt(j); // current line Line segment1 = outlines[i][1].SegmentAt(j); // current line //Get connected face of that segment int flattenID = e[fe[i][j]]; Tuple <int, int>[] edgeFacesAndEdge = efe[flattenID]; if (edgeFacesAndEdge.Length == 2) { int neiFID = (edgeFacesAndEdge[0].Item1 == i) ? 1 : 0; int neiF = edgeFacesAndEdge[neiFID].Item1; int nextNei = edgeFacesAndEdge[neiFID].Item2; Plane planeA = sidePlanes[neiF][MathUtil.Wrap(nextNei + 2, fe[neiF].Length)]; Plane planeB = sidePlanes[neiF][MathUtil.Wrap(nextNei + 0, fe[neiF].Length)]; Plane planeC = sidePlanes[neiF][MathUtil.Wrap(nextNei + 1, fe[neiF].Length)]; Plane planeD = sidePlanes[neiF][MathUtil.Wrap(nextNei + 3, fe[neiF].Length)]; //Rhino.RhinoApp.WriteLine(fe[neiF].Length.ToString() + " " + sidePlanes[neiF].Count.ToString() + " " + MathUtil.Wrap(nextNei - 1, fe[neiF].Length).ToString()); int nn = MathUtil.Wrap(nextNei - 1, fe[neiF].Length); //nextNei = fe[neiF][MathUtil.Wrap(nextNei - 1, fe[neiF].Length)]; //for(int k = 0; k < fe[neiF].Length; k++) { //int nextNei = k; //Rhino.RhinoApp.wr if (i == 11 && j == 3) { Rectangle3d rec = new Rectangle3d(planeA, 10, 10); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(outlinesCopy[i][0]); rec = new Rectangle3d(planeB, 10, 10); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec); //rec = new Rectangle3d(planeC, 10, 10); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec); } //Rhino.RhinoApp.WriteLine("ww"); bool flag = Rhino.Geometry.Intersect.Intersection.LinePlane(segment0, planeB, out double t); if (t > 0 && t < 1) { Point3d neiP0 = NGonsCore.PlaneUtil.LinePlane(segment0, planeB); outlinesCopy[i][0].Insert((int)Math.Ceiling(outlinesCopy[i][0].ClosestParameter(neiP0)), neiP0); Point3d neiP1 = NGonsCore.PlaneUtil.LinePlane(segment1, planeB); outlinesCopy[i][1].Insert((int)Math.Ceiling(outlinesCopy[i][1].ClosestParameter(neiP1)), neiP1); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(neiP0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(neiP1); } //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(neiP); // } } } //if (i == 11) { //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(outlinesCopy[i][0]); //} } for (int i = 0; i < facePlanes.Length; i++) { outlinesCopy[i][0].RemoveAt(0); outlinesCopy[i][1].RemoveAt(0); for (int j = 0; j < outlinesCopy[i][0].Count; j++) { Line line = new Line(outlinesCopy[i][0][j], outlinesCopy[i][1][j]); //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(line); Point3d pt = MeshUtilSimple.MeshRay(projectionMesh, line); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(pt); outlinesCopy[i][0][j] = pt; } outlinesCopy[i][0].Close(); outlinesCopy[i][1].Close(); } //Edge vectors Vector3d[] ev = new Vector3d[efe.Length]; } return(outlinesCopy); }
protected override void SolveInstance(IGH_DataAccess DA) { try { Mesh M = DA.Fetch <Mesh>("Mesh"); double D = DA.Fetch <double>("Offset"); int T = DA.Fetch <int>("Type"); double W = DA.Fetch <double>("Dist2"); double Tol = DA.Fetch <double>("Tol"); var mid = DA.FetchList <int>("Custom"); bool P = true; Polyline[] p0; Polyline[] p1; DataTree <Polyline> dt = new DataTree <Polyline>(); DataTree <Polyline> dtThickness = new DataTree <Polyline>(); if (D == 0) { switch (T) { case (1): base.Message = "No Offset \n Projection"; //output dt = new DataTree <Polyline>(); var polygons = M.ProjectedPolylinesToAveragePlane(P); for (int i = 0; i < M.Ngons.Count; i++) { dt.Add(polygons[i], new GH_Path(DA.Iteration, i)); } break; default: base.Message = "No Offset \n FaceEdgeBisector"; //Get edge planes and corner bisectors *----*----* Plane[][] bisePlanes; Plane[][] edgePlanes; M.GetEdgeAndBisectorPlanes(out bisePlanes, out edgePlanes); dt = new DataTree <Polyline>(); //Get Outlines p0 = M.GetPolylines(); for (int i = 0; i < M.Ngons.Count; i++) { Plane plane = p0[i].GetPlane(P); dt.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); if (W > 0) { plane = plane.MovePlanebyAxis(-W * 0.5); dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); plane = plane.MovePlanebyAxis(W); dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); plane = plane.MovePlanebyAxis(-W * 0.5); } } break; } DA.SetDataList(0, new Mesh[] { M }); } else { //Offset two meshes in both sides Mesh m0 = M.DuplicateMesh(); Mesh m1 = M.DuplicateMesh(); m0 = m0.Offset(D * 0.5); m1 = m1.Offset(-D * 0.5); switch (T) { case (1): //case (2): base.Message = "Offset \n Projection"; //output Mesh mA = M.DuplicateMesh(); Mesh mB = M.DuplicateMesh(); Mesh mC = M.DuplicateMesh(); Mesh mD = M.DuplicateMesh(); Mesh mA_ = M.DuplicateMesh(); Mesh mB_ = M.DuplicateMesh(); Mesh mE = M.DuplicateMesh(); Mesh mF = M.DuplicateMesh(); mA = mA.Offset(-D * 0.5 + W * 0.5); mB = mB.Offset(-D * 0.5 - W * 0.5); mC = mC.Offset(D * 0.5 + W * 0.5); mD = mD.Offset(D * 0.5 - W * 0.5); mA_ = mA_.Offset(-D * 0.5); mB_ = mB_.Offset(D * 0.5); mE = mE.Offset(W * 0.5); mF = mF.Offset(-W * 0.5); dtThickness = new DataTree <Polyline>(); dt = new DataTree <Polyline>(); //Rhino.RhinoApp.WriteLine("Hi"); var a = mA.ProjectedPolylinesToAveragePlane(P); var b = mB.ProjectedPolylinesToAveragePlane(P); var c = mC.ProjectedPolylinesToAveragePlane(P); var d = mD.ProjectedPolylinesToAveragePlane(P); var a_ = mA_.ProjectedPolylinesToAveragePlane(P); var b_ = mB_.ProjectedPolylinesToAveragePlane(P); var e = mE.ProjectedPolylinesToAveragePlane(P); var f = mF.ProjectedPolylinesToAveragePlane(P); for (int i = 0; i < a.Length; i++) { dtThickness.Add(a[i], new GH_Path(DA.Iteration, i)); dtThickness.Add(b[i], new GH_Path(DA.Iteration, i)); if (mid.Contains(i)) { dtThickness.Add(e[i], new GH_Path(DA.Iteration, i)); dtThickness.Add(f[i], new GH_Path(DA.Iteration, i)); } dtThickness.Add(c[i], new GH_Path(DA.Iteration, i)); dtThickness.Add(d[i], new GH_Path(DA.Iteration, i)); dt.Add(a_[i], new GH_Path(DA.Iteration, i)); dt.Add(b_[i], new GH_Path(DA.Iteration, i)); } break; default: base.Message = "Offset \n FaceEdgeBisector"; //Get edge planes and corner bisectors *----*----* Plane[][] bisePlanes; Plane[][] edgePlanes; M.GetEdgeAndBisectorPlanes(out bisePlanes, out edgePlanes); DataTree <Plane> pls = new DataTree <Plane>(); for (int i = 0; i < bisePlanes.Length; i++) { pls.AddRange(bisePlanes[i], new GH_Path(DA.Iteration, 0, i)); pls.AddRange(edgePlanes[i], new GH_Path(DA.Iteration, 1, i)); } //EdgePlanes = pls; DA.SetDataTree(3, pls); dt = new DataTree <Polyline>(); dtThickness = new DataTree <Polyline>(); //Get Outlines p0 = M.GetPolylines(); p1 = M.GetPolylines(); for (int i = 0; i < M.Ngons.Count; i++) { Plane plane = p0[i].GetPlane(P); plane = plane.MovePlanebyAxis(D * 0.5); dt.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); if (W > 0) { plane = plane.MovePlanebyAxis(-W * 0.5); dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); plane = plane.MovePlanebyAxis(W); dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); plane = plane.MovePlanebyAxis(-W * 0.5); } plane = plane.MovePlanebyAxis(-D); dt.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); if (W > 0) { plane = plane.MovePlanebyAxis(-W * 0.5); dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); plane = plane.MovePlanebyAxis(W); dtThickness.Add(PolylineUtil.OutlineFromFaceEdgeCorner(plane, edgePlanes[i], bisePlanes[i], T, Tol), new GH_Path(DA.Iteration, i)); plane = plane.MovePlanebyAxis(-W * 0.5); } } break; } //Output //OffsetMesh = new Mesh[] { m0, m1 }; this.PreparePreview(m0, DA.Iteration, dt.AllData(), false); DA.SetDataList(0, new Mesh[] { m0, m1 }); } DA.SetDataTree(1, dt); DA.SetDataTree(2, dtThickness); //ProjectedPolylines = dt; //Thickness = dtThickness; }catch (Exception e) { Rhino.RhinoApp.WriteLine(e.ToString()); } }