public DataTree <Line> GetDowels(double radius = 0.075, int count = 8) { DataTree <Line> dt = new DataTree <Line>(); for (int i = 0; i < this._nexors.Count; i++) { if (this._nexors[i].isNexor != 0) { var path = new GH_Path(i); Point3d c = (this._nexors[i].endPl0.Origin + this._nexors[i].endPl1.Origin) * 0.5; int dir = (c.DistanceToSquared(this._nexors[i].endPl0.Origin + this._nexors[i].endPl0.ZAxis) < c.DistanceToSquared(this._nexors[i].endPl0.Origin - this._nexors[i].endPl0.ZAxis)) ? -1 : 1; Plane plane = this._nexors[i].endPl0.ChangeOrigin(PlaneUtil.LinePlane(this._nexors[i].pipe.line, this._nexors[i].endPl0)); Circle circle = new Circle(plane, radius); Curve curve = circle.ToNurbsCurve(); curve.DivideByCount(count, true, out Point3d[] pts); foreach (Point3d p in pts) { Line line = new Line(p, this._nexors[i].endPl0.ZAxis * dir * 0.15); dt.Add(line, path); //line.Bake(); } plane = this._nexors[i].endPl1.ChangeOrigin(PlaneUtil.LinePlane(this._nexors[i].pipe.line, this._nexors[i].endPl1)); circle = new Circle(plane, radius); curve = circle.ToNurbsCurve(); curve.DivideByCount(count, true, out Point3d[] pts1); dir = (c.DistanceToSquared(this._nexors[i].endPl1.Origin + this._nexors[i].endPl1.ZAxis) < c.DistanceToSquared(this._nexors[i].endPl1.Origin - this._nexors[i].endPl1.ZAxis)) ? -1 : 1; foreach (Point3d p in pts1) { Line line = new Line(p, this._nexors[i].endPl1.ZAxis * dir * 0.15); dt.Add(line, path); //line.Bake(); } //Rhino.RhinoDoc.ActiveDoc.Objects.AddCircle(circle); } } 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); }
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 void CreateCut(int segmentID, Plane jointPlane0, Plane jointPlane1, double length_, ref Panel jointPanel, bool bake = false) //, ref Panel neiPanel,) { { double e = 0; Polyline cut = new Polyline(); Line segment0 = contourNoJoints[0].SegmentAt(segmentID); Line segment1 = contourNoJoints[1].SegmentAt(segmentID); double dist = this.plane.Origin.DistanceTo(segment0.PointAt(0.5)); double length = length_;// * dist * 0.01; //Rhino.RhinoApp.WriteLine(dist.ToString()); //Intersect plate edge line and joint plane offsets Point3d edgePoint00 = PlaneUtil.LinePlane(segment0, jointPlane0); Point3d edgePoint01 = PlaneUtil.LinePlane(segment0, jointPlane1); Point3d edgePoint10 = PlaneUtil.LinePlane(segment1, jointPlane0); Point3d edgePoint11 = PlaneUtil.LinePlane(segment1, jointPlane1); //Get direction of a cut Vector3d v00 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane0); Vector3d v01 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane1); Vector3d v10 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane0); Vector3d v11 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane1); //Really f****d up way of checking which direction plane must be offseted for correct cut direction Point3d p0 = mesh.ClosestPoint((segment0.PointAt(0.5) + v00 * 10)); Point3d p1 = mesh.ClosestPoint((segment0.PointAt(0.5) - v00 * 10)); //bool moveFlag = (segment0.PointAt(0.5) + v00*10).DistanceTo(planeOffset0.Origin) < (segment0.PointAt(0.5) - v00*10).DistanceTo(planeOffset0.Origin); bool moveFlag = p0.DistanceToSquared((segment0.PointAt(0.5) + v00 * 10)) < p1.DistanceToSquared((segment0.PointAt(0.5) - v00 * 10)); if (bake) { //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(planeOffset0.Origin); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(segment0.PointAt(0.5) + v00*100); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(segment0.PointAt(0.5) - v00*100); } //Moved Points Point3d innerPoint00 = (moveFlag) ? edgePoint00 + (v00 * length) : edgePoint00 - (v00 * length); Point3d innerPoint01 = (moveFlag) ? edgePoint01 + (v01 * length) : edgePoint01 - (v01 * length); Point3d innerPoint10 = (moveFlag) ? edgePoint10 + (v10 * length) : edgePoint10 - (v10 * length); Point3d innerPoint11 = (moveFlag) ? edgePoint11 + (v11 * length) : edgePoint11 - (v11 * length); Point3d innerPointCenter = (innerPoint00 + innerPoint01 + innerPoint10 + innerPoint11) * 0.25; Plane perpPlane = new Plane(innerPointCenter, jointPlane0.Normal, Vector3d.CrossProduct(planeOffset0.Normal, v00)); innerPoint00 = perpPlane.RayPlane(edgePoint00, v00); innerPoint01 = perpPlane.RayPlane(edgePoint01, v01); innerPoint10 = perpPlane.RayPlane(edgePoint10, v10); innerPoint11 = perpPlane.RayPlane(edgePoint11, v11); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(perpPlane, 50, 50)); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(jointPlane0, 50, 50)); //Middle points and projection to plane Point3d innerPointMid00 = (moveFlag) ? edgePoint00 + (v00 * length * 0.5) : edgePoint00 - (v00 * length * 0.5); Point3d innerPointMid01 = (moveFlag) ? edgePoint01 + (v01 * length * 0.5) : edgePoint01 - (v01 * length * 0.5); Point3d innerPointMid10 = (moveFlag) ? edgePoint10 + (v10 * length * 0.5) : edgePoint10 - (v10 * length * 0.5); Point3d innerPointMid11 = (moveFlag) ? edgePoint11 + (v11 * length * 0.5) : edgePoint11 - (v11 * length * 0.5); Point3d innerPointMid = (innerPointMid00 + innerPointMid01 + innerPointMid10 + innerPointMid11) * 0.25; Plane perpPlaneMid = new Plane(innerPointMid, jointPlane0.Normal, perpPlane.YAxis); innerPointMid00 = perpPlaneMid.RayPlane(edgePoint00, v00); innerPointMid01 = perpPlaneMid.RayPlane(edgePoint01, v01); innerPointMid10 = perpPlaneMid.RayPlane(edgePoint10, v10); innerPointMid11 = perpPlaneMid.RayPlane(edgePoint11, v11); //It is not closest point because the connection is not perpendicular to two adjacent plates //It might be close to perpendicular but not possible Polyline cut0 = new Polyline(new Point3d[] { edgePoint00, innerPointMid00 + v00 * e, innerPointMid01 + v01 * e, edgePoint01 });//perpPlane.ClosestPoint Polyline cut1 = new Polyline(new Point3d[] { edgePoint10, innerPointMid10 + v10 * e, innerPointMid11 + v11 * e, edgePoint11 }); this.cuts.Add(cut0); this.cuts.Add(cut1); Polyline cutNei0 = new Polyline(new Point3d[] { innerPoint00, innerPointMid00 + v00 * -e, innerPointMid10 + v01 * -e, innerPoint10 });//perpPlane.ClosestPoint Polyline cutNei1 = new Polyline(new Point3d[] { innerPoint01, innerPointMid01 + v10 * -e, innerPointMid11 + v11 * -e, innerPoint11 }); jointPanel.cuts.Add(cutNei0); jointPanel.cuts.Add(cutNei1); contour[0].InsertPolyline(cut0); contour[1].InsertPolyline(cut1); jointPanel.contour[0].InsertPolyline(cutNei0); jointPanel.contour[1].InsertPolyline(cutNei1); if (bake) { Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut0); Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut1); } //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cutNei0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cutNei1); }
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()); } }
public void CreateCut(int segmentID, Plane jointPlane0, Plane jointPlane1, double length, ref Panel jointPanel) //, ref Panel neiPanel,) { { double e = 0; Polyline cut = new Polyline(); Line segment0 = contourNoJoints[0].SegmentAt(segmentID); Line segment1 = contourNoJoints[1].SegmentAt(segmentID); //Intersect plate edge line and joint plane offsets Point3d edgePoint00 = PlaneUtil.LinePlane(segment0, jointPlane0); Point3d edgePoint01 = PlaneUtil.LinePlane(segment0, jointPlane1); Point3d edgePoint10 = PlaneUtil.LinePlane(segment1, jointPlane0); Point3d edgePoint11 = PlaneUtil.LinePlane(segment1, jointPlane1); //Get direction of a cut Vector3d v00 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane0); Vector3d v01 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane1); Vector3d v10 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane0); Vector3d v11 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane1); bool moveFlag = (segment0.PointAt(0.5) + v00).DistanceTo(planeOffset0.Origin) < (segment0.PointAt(0.5) - v00).DistanceTo(planeOffset0.Origin); //Moved Points Point3d innerPoint00 = (moveFlag) ? edgePoint00 + (v00 * length) : edgePoint00 - (v00 * length); Point3d innerPoint01 = (moveFlag) ? edgePoint01 + (v01 * length) : edgePoint01 - (v01 * length); Point3d innerPoint10 = (moveFlag) ? edgePoint10 + (v10 * length) : edgePoint10 - (v10 * length); Point3d innerPoint11 = (moveFlag) ? edgePoint11 + (v11 * length) : edgePoint11 - (v11 * length); Point3d innerPointCenter = (innerPoint00 + innerPoint01 + innerPoint10 + innerPoint11) * 0.25; Plane perpPlane = new Plane(innerPointCenter, jointPlane0.Normal, Vector3d.CrossProduct(planeOffset0.Normal, v00)); innerPoint00 = perpPlane.RayPlane(edgePoint00, v00); innerPoint01 = perpPlane.RayPlane(edgePoint01, v01); innerPoint10 = perpPlane.RayPlane(edgePoint10, v10); innerPoint11 = perpPlane.RayPlane(edgePoint11, v11); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(perpPlane, 50, 50)); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(jointPlane0, 50, 50)); //Middle points and projection to plane Point3d innerPointMid00 = (moveFlag) ? edgePoint00 + (v00 * length * 0.5) : edgePoint00 - (v00 * length * 0.5); Point3d innerPointMid01 = (moveFlag) ? edgePoint01 + (v01 * length * 0.5) : edgePoint01 - (v01 * length * 0.5); Point3d innerPointMid10 = (moveFlag) ? edgePoint10 + (v10 * length * 0.5) : edgePoint10 - (v10 * length * 0.5); Point3d innerPointMid11 = (moveFlag) ? edgePoint11 + (v11 * length * 0.5) : edgePoint11 - (v11 * length * 0.5); Point3d innerPointMid = (innerPointMid00 + innerPointMid01 + innerPointMid10 + innerPointMid11) * 0.25; Plane perpPlaneMid = new Plane(innerPointMid, jointPlane0.Normal, perpPlane.YAxis); innerPointMid00 = perpPlaneMid.RayPlane(edgePoint00, v00); innerPointMid01 = perpPlaneMid.RayPlane(edgePoint01, v01); innerPointMid10 = perpPlaneMid.RayPlane(edgePoint10, v10); innerPointMid11 = perpPlaneMid.RayPlane(edgePoint11, v11); //It is not closest point because the connection is not perpendicular to two adjacent plates //It might be close to perpendicular but not possible Polyline cut0 = new Polyline(new Point3d[] { edgePoint00, innerPointMid00 + v00 * e, innerPointMid01 + v01 * e, edgePoint01 });//perpPlane.ClosestPoint Polyline cut1 = new Polyline(new Point3d[] { edgePoint10, innerPointMid10 + v10 * e, innerPointMid11 + v11 * e, edgePoint11 }); this.cuts.Add(cut0); this.cuts.Add(cut1); Polyline cutNei0 = new Polyline(new Point3d[] { innerPoint00, innerPointMid00 + v00 * -e, innerPointMid10 + v01 * -e, innerPoint10 });//perpPlane.ClosestPoint Polyline cutNei1 = new Polyline(new Point3d[] { innerPoint01, innerPointMid01 + v10 * -e, innerPointMid11 + v11 * -e, innerPoint11 }); jointPanel.cuts.Add(cutNei0); jointPanel.cuts.Add(cutNei1); contour[0].InsertPolyline(cut0); contour[1].InsertPolyline(cut1); jointPanel.contour[0].InsertPolyline(cutNei0); jointPanel.contour[1].InsertPolyline(cutNei1); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut1); }
//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); }
/// <summary> ///For center axis I need three planes: ///A - Edge plane ///B - Bottom Plane ///C - Section Plane ///Also two points ///And radius /// </summary> /// <param name="p"></param> /// <returns></returns> public DataTree <Polyline> RoundBeams(NGonsCore.MeshProps p, double radius = 0.075) { var dt = new DataTree <Polyline>(); 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) { Plane edgePlane = this[i, j].ePl; Plane sectionPlane = new Plane(this[i, j].ePl.Origin, this[i, j].ePl.YAxis, this[i, j].ePl.ZAxis); Plane bottomPlane = this[i, j].ePl90Offset; //for getting the points Point3d p1 = PlaneUtil.PlanePlanePlane(this[i, j].foPl[0], this[i, j].foPl[1].MovePlanebyAxis(this.plateThickness), sectionPlane); Point3d p0 = PlaneUtil.PlanePlanePlane(this[i, j].fcPl[2], this[i, j].fcPl[1].MovePlanebyAxis(this.plateThickness), sectionPlane); Point3d pc = PlaneUtil.PlanePlanePlane(this[i, j].fcPl[0], this[i, j].fcPl_foPl, sectionPlane); Point3d po = PlaneUtil.PlanePlanePlane(this[i, j].foPl[2], this[i, j].fcPl_foPl, sectionPlane); //pc.Bake(); //po.Bake(); //if (i == 20) { Line line = this[i, j].line; Circle circle = CircleUtil.GetCircleCenter(edgePlane, bottomPlane, sectionPlane, new List <Point3d> { p0, p1 }, radius); Vector3d v = circle.Center - line.From; line.Transform(Transform.Translation(v)); //Rhino.RhinoDoc.ActiveDoc.Objects.AddCircle(circle); //Rhino.RhinoApp.WriteLine(p.M.IsNaked(p.M._meshE(i, j)).ToString()); int[] on = (p.M.IsNaked(fe[j])) ? new int[] { i, (j + 1).Wrap(fe.Length) } : p.M._OppositeFE(i, j, 1); int[] op = (p.M.IsNaked(fe[j])) ? new int[] { i, (j - 1).Wrap(fe.Length) } : p.M._OppositeFE(i, j, -1); bool onFlag = this[on[0], on[1]].isNexor == 0; bool opFlag = this[op[0], op[1]].isNexor == 0; if (this[on[0], on[1]].isNexor == 0) { on = p.M._OppositeFE(on[0], on[1]); } if (this[op[0], op[1]].isNexor == 0) { op = p.M._OppositeFE(op[0], op[1]); } Plane pl0 = onFlag ? this[on[0], on[1]].foPl[0] : this[on[0], on[1]].fcPl[2]; Plane pl1 = opFlag ? this[op[0], op[1]].foPl[0] : this[op[0], op[1]].fcPl[2]; pl0 = this[i, j].endPl0; pl1 = this[i, j].endPl1; if (this[on[0], on[1]].isNexor != 0 && this[op[0], op[1]].isNexor != 0) { line = new Line(PlaneUtil.LinePlane(line, this[i, j].endPl0), PlaneUtil.LinePlane(line, this[i, j].endPl1)); line.Extend(0.1, 0.1); //line.Transform(Transform.Scale(line.Center(), 2)); this[i, j].pipe = NGonsCore.PipeUtil.CreatePipe( line, this[i, j].id, sectionPlane, radius, pl0.MovePlanebyAxis(0.01, this[i, j].line.Center(), 2, false), pl1.MovePlanebyAxis(0.01, this[i, j].line.Center(), 2, false), 10, -1, true); // Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(pipe.meshloft); //Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(this[i, j].pipe.breploft); } //} } } } return(dt); }
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) { Mesh M = DA.Fetch <Mesh>("Mesh"); GH_Structure <GH_Curve> Curves = DA.FetchTree <GH_Curve>("Panels"); DataTree <Polyline> C = new DataTree <Polyline>(); GH_Structure <GH_Vector> edgeVectors = DA.FetchTree <GH_Vector>("EdgeVectors"); DataTree <Vector3d> EVec = new DataTree <Vector3d>(); 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"); GH_Structure <GH_Curve> CurvesChamfer = DA.FetchTree <GH_Curve>("PanelsChamfer"); DataTree <Polyline> CChamfer = new DataTree <Polyline>(); for (int i = 0; i < Curves.Branches.Count; i++) { for (int j = 0; j < Curves.get_Branch(i).Count; j++) { Polyline polyline; Curves.get_DataItem(Curves.Paths[i], j).Value.TryGetPolyline(out polyline); C.Add(polyline, Curves.Paths[i]); } } if (CurvesChamfer.DataCount == Curves.DataCount) { for (int i = 0; i < Curves.Branches.Count; i++) { for (int j = 0; j < Curves.get_Branch(i).Count; j++) { Polyline polyline; CurvesChamfer.get_DataItem(Curves.Paths[i], j).Value.TryGetPolyline(out polyline); CChamfer.Add(polyline, Curves.Paths[i]); } } } for (int i = 0; i < edgeVectors.Branches.Count; i++) { for (int j = 0; j < edgeVectors.get_Branch(i).Count; j++) { EVec.Add(edgeVectors.get_DataItem(edgeVectors.Paths[i], j).Value, edgeVectors.Paths[i]); } } //Solution DataTree <Polyline> diagonalConnections = new DataTree <Polyline>(); int divisions = Math.Max(1, D); double length = 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(); DataTree <Polyline> Ccut = new DataTree <Polyline>(); for (int i = 0; i < C.BranchCount; i++) { for (int j = 0; j < C.Branch(i).Count; j++) { if (CurvesChamfer.DataCount == Curves.DataCount) { Ccut.Add(new Polyline(CChamfer.Branch(i)[j]), new GH_Path(CChamfer.Path(i))); } else { Ccut.Add(new Polyline(C.Branch(i)[j]), new GH_Path(C.Path(i))); //Rhino.RhinoApp.WriteLine(CChamfer.DataCount.ToString() + " " + Curves.DataCount.ToString()); } } } DataTree <Vector3d> EV = new DataTree <Vector3d>(); if (EVec.DataCount == 0) { foreach (int ee in e) { if (M.TopologyEdges.GetConnectedFaces(ee).Length != 1) { if (Center) { int[] facePair = efDict[ee]; Vector3d insertionVec = centers[facePair[0]] - centers[facePair[1]]; insertionVec.Unitize(); EV.Add(insertionVec, new GH_Path(ee)); //Line li = new Line(centers[facePair[0]] , centers[facePair[1]]); //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(li); } else { EV.Add(NGonsCore.VectorUtil.BisectorVector(M.TopologyEdges.EdgeLine(ee), M.GetNGonNormal(efDict[ee][0])), new GH_Path(ee)); } } } } else { EV = EVec; } DataTree <Polyline> recJoints = new DataTree <Polyline>(); for (int i = 0; i < EV.BranchCount; i++) { GH_Path p = EV.Path(i); int ecur = p.Indices[0]; int f0 = efDict[ecur][0]; int f1 = efDict[ecur][1]; //Divide line into points Line line = M.TopologyEdges.EdgeLine(ecur); Point3d[] pts = NGonsCore.PointUtil.InterpolatePoints(line.From, line.To, divisions, false); Point3d[] pts0 = new Point3d[pts.Length]; Point3d[] pts1 = new Point3d[pts.Length]; //Get average normal between faces Vector3d edgeNormal = M.GetNGonNormal(f0) + M.GetNGonNormal(f1); edgeNormal.Unitize(); Vector3d cross = Vector3d.CrossProduct(edgeNormal, EV.Branch(p)[0]); cross.Unitize(); //Get line planes Plane[] edgePlanes = new Plane[pts.Length]; Plane edgePlane90 = new Plane(line.PointAt(0.5), cross, edgeNormal); for (int j = 0; j < pts.Length; j++) { Vector3d v = EV.Branch(p)[0]; v.Unitize(); edgePlanes[j] = new Plane(pts[j], v, edgeNormal); } Point3d[][] edgePoints = new Point3d[edgePlanes.Length][]; for (int j = 0; j < edgePlanes.Length; j++) //C.Branch(f0).Count { Polyline[] rectangleWithoutJoints = new Polyline[] { new Polyline(), new Polyline() }; List <Polyline>[] rectangleJoints = new List <Polyline>[] { new List <Polyline>(), new List <Polyline>() }; foreach (int fn in efDict[ecur]) { int e0 = Array.IndexOf(fe[fn], ecur); edgePoints[j] = new Point3d[C.Branch(fn).Count]; Polyline[] perpJoint = new Polyline[C.Branch(fn).Count]; Polyline recJoint0 = new Polyline(); Polyline recJoint1 = new Polyline(); for (int k = 0; k < C.Branch(fn).Count; k++) { if (k % 2 == 0 && k != 0) { //rectangleJoints[0].Add(recJoint0); //rectangleJoints[1].Add(recJoint1); recJoint0.Clear(); recJoint1.Clear(); } Line segment = C.Branch(fn)[k].SegmentAt(e0); Plane planeOff0 = edgePlanes[j].MovePlanebyAxis(W * 0.5); Plane planeOff1 = edgePlanes[j].MovePlanebyAxis(-W * 0.5); Plane planeFace = C.Branch(fn)[k].plane(); Plane plane3 = new Plane(planeFace.Origin, edgePlanes[j].Normal, planeFace.Normal); //Face0 edge points Point3d edgePoint0 = PlaneUtil.LinePlane(segment, planeOff0); Point3d edgePoint1 = PlaneUtil.LinePlane(segment, planeOff1); //Inner Points Vector3d v0 = PlaneUtil.PlanePlaneVec(planeFace, planeOff0); Vector3d v1 = PlaneUtil.PlanePlaneVec(planeFace, planeOff1); bool moveFlag = (segment.PointAt(0.5) + v0).DistanceTo(planeFace.Origin) < (segment.PointAt(0.5) - v0).DistanceTo(planeFace.Origin); bool flagMod = j % 2 == 0; bool flagFace = efDict[ecur][0] == fn; flagMod = false; //double scalarLength = (centers[fn] - edgePlanes[j].Origin).Length*(double)Math.Abs(length); if (L < 0) { length = (centers[fn] - edgePlanes[j].Origin).Length * (double)Math.Abs(L); } //length = (centers[fn] - edgePlanes[j].Origin).Length*1; Point3d innerPoint0 = (moveFlag) ? edgePoint0 + (v0 * length) : edgePoint0 - (v0 * length); Point3d innerPoint1 = (moveFlag) ? edgePoint1 + (v1 * length) : edgePoint1 - (v1 * length); if (Finger) { innerPoint0 = (!moveFlag && !Finger) ? edgePoint0 + (v0 * length) : edgePoint0 - (v0 * length); innerPoint1 = (!moveFlag && !Finger) ? edgePoint1 + (v1 * length) : edgePoint1 - (v1 * length); } //Point3d innerPoint0 = edgePoint0 +(v0 * L); //Point3d innerPoint1 = edgePoint1 +(v1 * L) ; Polyline polylinep0 = new Polyline(new Point3d[] { edgePoint0, innerPoint0, innerPoint1, edgePoint1 }); // Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(polylinep0); Line guideLine0 = new Line(edgePoint0, innerPoint0); Line guideLine1 = new Line(edgePoint1, innerPoint1); Point3d mid = (innerPoint1 + innerPoint0) * 0.5; innerPoint0 = guideLine0.ClosestPoint(mid, false); innerPoint1 = guideLine1.ClosestPoint(mid, false); Point3d center = (edgePoint0 + innerPoint0 + innerPoint1 + edgePoint1) * 0.25; Point3d center0 = guideLine0.ClosestPoint(center, false); Point3d center1 = guideLine1.ClosestPoint(center, false); perpJoint[k] = new Polyline(new Point3d[] { innerPoint0, center0, center1, innerPoint1 }); Polyline polyline0 = new Polyline(new Point3d[] { edgePoint0, center0, center1, edgePoint1 }); //finger joints or standard if (Finger) { if (efDict[ecur][0] == fn) { Ccut.Branch(efDict[ecur][0])[k].InsertPolyline(polyline0);//offset needed } else { Ccut.Branch(efDict[ecur][1])[k].InsertPolyline(polyline0);//offset needed } } else { Ccut.Branch(fn)[k].InsertPolyline(polyline0);//offset needed } if (fn == efDict[ecur][0]) { if (k == 1 || k == NGonsCore.MathUtil.Wrap(C.Branch(fn).Count - 2, C.Branch(fn).Count)) { rectangleWithoutJoints[0].Add(innerPoint0); rectangleWithoutJoints[1].Add(innerPoint1); } } else { if (k == 1) { rectangleWithoutJoints[0].Add(innerPoint0); rectangleWithoutJoints[1].Add(innerPoint1); } if (k == NGonsCore.MathUtil.Wrap(C.Branch(fn).Count - 2, C.Branch(fn).Count)) { rectangleWithoutJoints[0].Insert(2, innerPoint0); rectangleWithoutJoints[1].Insert(2, innerPoint1); } } // Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(innerPoint0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(center0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(innerPoint1); // Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(recJoint0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(recJoint1); if (k % 2 == 0) { recJoint0.Add(innerPoint0); recJoint0.Add(center0); recJoint1.Add(innerPoint1); recJoint1.Add(center1); } else { recJoint0.Add(center0); recJoint0.Add(innerPoint0); recJoint1.Add(center1); recJoint1.Add(innerPoint1); } if (k % 2 == 1) { rectangleJoints[0].Add(new Polyline(recJoint0)); rectangleJoints[1].Add(new Polyline(recJoint1)); } if (k % 2 == 1) { //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(recJoint0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(recJoint1); } //edgePoints[j][k] = edgePoint0; // Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(edgePoint0); // Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(edgePoint1); // Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(innerPoint0); // Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(innerPoint1); // Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(polyline0); } } for (int m = 0; m < rectangleWithoutJoints.Length; m++) { Line l0 = CurveUtil.ExtendLine(rectangleWithoutJoints[m].SegmentAt(0), height); Line l1 = CurveUtil.ExtendLine(rectangleWithoutJoints[m].SegmentAt(2), height); if (l0.From.DistanceTo(l1.From) < l0.From.DistanceTo(l1.To)) { l1.Flip(); } rectangleWithoutJoints[m] = new Polyline(new Point3d[] { l0.From, l0.To, l1.From, l1.To, l0.From }); // Line line } for (int m = 0; m < rectangleJoints[0].Count; m++) { //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(rectangleJoints[0][j]); rectangleWithoutJoints[0].InsertPolyline(rectangleJoints[0][m]); rectangleWithoutJoints[1].InsertPolyline(rectangleJoints[1][m]); } //try make special joint if (Custom >= 0 && C.Branch(0).Count == 4) { Polyline rebuild0 = new Polyline(); Polyline rebuild1 = new Polyline(); for (int m = 2; m < 18; m++) { if (m == 2) { Vector3d v0 = rectangleWithoutJoints[0][m] - rectangleWithoutJoints[0][m + 1]; v0.Unitize(); rebuild0.Add(rectangleWithoutJoints[0][m] + v0 * Custom); rebuild1.Add(rectangleWithoutJoints[1][m] + v0 * Custom); } else if (m == 17) { Vector3d v0 = rectangleWithoutJoints[0][17] - rectangleWithoutJoints[0][16]; v0.Unitize(); rebuild0.Add(rectangleWithoutJoints[0][17] + v0 * Custom); rebuild1.Add(rectangleWithoutJoints[1][17] + v0 * Custom); } else { rebuild0.Add(rectangleWithoutJoints[0][m]); rebuild1.Add(rectangleWithoutJoints[1][m]); } } rebuild0.Close(); rebuild1.Close(); rectangleWithoutJoints[0] = rebuild0; rectangleWithoutJoints[1] = rebuild1; } recJoints.AddRange(rectangleWithoutJoints, new GH_Path(ecur)); } //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(rectangleWithoutJoints[0]); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(rectangleWithoutJoints[1]); //A = edgePlanes; } DA.SetDataTree(0, Ccut); DA.SetDataTree(1, recJoints); //DC = diagonalConnections; //Panels = Ccut; //Joints = recJoints; }