protected override void SolveInstance(IGH_DataAccess DA) { Brep Brep = null; var Curves = new List <Curve>();; var Points = new List <Point3d>();; if (!DA.GetData("Brep", ref Brep)) { return; } bool hasCurves = DA.GetDataList("Curves", Curves); bool hasPoints = DA.GetDataList("Points", Points); if (Brep != null) { Unroller unroller = new Unroller(Brep); if (hasCurves) { unroller.AddFollowingGeometry(Curves); } if (hasPoints) { unroller.AddFollowingGeometry(Points); } TextDot[] dots; Point3d[] pts; Curve[] unrolledCrvs; unroller.ExplodeOutput = false; var B = unroller.PerformUnroll(out unrolledCrvs, out pts, out dots); var C = unrolledCrvs; var P = pts; DA.SetDataList("Brep", B); DA.SetDataList("Curves", C); DA.SetDataList("Points", P); } }
public static Mesh ConvertBrepToMesh(Brep brep, List <Curve> curves, List <Point3d> points, double meshSize, List <Parameters.GsaMember1d> mem1ds = null, List <Parameters.GsaNode> nodes = null) { Brep in_brep = brep.DuplicateBrep(); in_brep.Faces.ShrinkFaces(); // set up unroller Unroller unroller = new Unroller(in_brep); List <Curve> memcrvs = new List <Curve>(); if (mem1ds != null) { memcrvs = mem1ds.ConvertAll(x => (Curve)x.PolyCurve); unroller.AddFollowingGeometry(memcrvs); } List <Point3d> nodepts = new List <Point3d>(); if (nodes != null) { nodepts = nodes.ConvertAll(x => x.Point); unroller.AddFollowingGeometry(nodepts); } unroller.AddFollowingGeometry(points); unroller.AddFollowingGeometry(curves); unroller.RelativeTolerance = 10 ^ 32; //unroller.AbsoluteTolerance = 1000; // create list of flattened geometry Point3d[] inclPts; Curve[] inclCrvs; TextDot[] unused; // perform unroll Brep[] flattened = unroller.PerformUnroll(out inclCrvs, out inclPts, out unused); // create 2d member from flattened geometry Parameters.GsaMember2d mem = new Parameters.GsaMember2d(flattened[0], inclCrvs.ToList(), inclPts.ToList()); mem.Member.MeshSize = meshSize; // add to temp list for input in assemble function List <Parameters.GsaMember2d> mem2ds = new List <Parameters.GsaMember2d>(); mem2ds.Add(mem); if (mem1ds != null) { for (int i = 0; i < mem1ds.Count; i++) { Parameters.GsaMember1d mem1d = new Parameters.GsaMember1d(inclCrvs[i]); mem1d.Member.MeshSize = mem1ds[i].Member.MeshSize; mem1ds[i] = mem1d; } } if (nodes != null) { for (int i = 0; i < nodes.Count; i++) { nodes[i].Point = inclPts[i]; } } // assemble temp model Model model = Util.Gsa.ToGSA.Assemble.AssembleModel(null, mem2ds, mem1ds, nodes); // call the meshing algorithm model.CreateElementsFromMembers(); // extract elements from model Tuple <List <Parameters.GsaElement1dGoo>, List <Parameters.GsaElement2dGoo>, List <Parameters.GsaElement3dGoo> > elementTuple = Util.Gsa.FromGSA.GetElements(model.Elements(), model.Nodes(), model.Sections(), model.Prop2Ds()); List <Parameters.GsaElement2dGoo> elem2dgoo = elementTuple.Item2; Mesh mesh = elem2dgoo[0].Value.Mesh; Surface flat = flattened[0].Surfaces[0]; Surface orig = in_brep.Surfaces[0]; MeshVertexList vertices = mesh.Vertices; for (int i = 0; i < vertices.Count; i++) { flat.ClosestPoint(vertices.Point3dAt(i), out double u, out double v); Point3d mapVertex = orig.PointAt(u, v); vertices.SetVertex(i, mapVertex); } mesh.Faces.ConvertNonPlanarQuadsToTriangles(GhSA.Units.Tolerance, Rhino.RhinoMath.DefaultAngleTolerance, 0); return(mesh); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { //---- Declareing --------------------------------------------------------------------------- GH_Structure <GH_Brep> AllStripes; DA.GetDataTree("Triloop Stipes", out AllStripes); GH_Structure <GH_Point> AllPoints; DA.GetDataTree("Points", out AllPoints); bool Reorient = false; DA.GetData <bool>("Merge Stripes", ref Reorient); bool Switch = false; DA.GetData <bool>("Switch", ref Switch); int Seam = 0; DA.GetData <int>("Seam", ref Seam); DataTree <Brep> AllUnrolledBreps = new DataTree <Brep>(); DataTree <Brep> ForReorientBreps = new DataTree <Brep>(); DataTree <Plane> AllOrientPlanes = new DataTree <Plane>(); DataTree <Curve> AllSharedCurves = new DataTree <Curve>(); DataTree <Point3d> AllUnrolledPoints = new DataTree <Point3d>(); //---- End Declareing ----------------------------------------------------------------------- //---- Functions ---------------------------------------------------------------------------- #region Unroll for (int i = 0; i < AllStripes.Branches.Count; i++) { GH_Path pth = new GH_Path(i); GH_Path originalPath = AllStripes.Paths[i]; int stripecounter = 0; foreach (GH_Brep gbrep in AllStripes[i]) { Unroller unroll = new Unroller(gbrep.Value); // Add points to unroll with if (AllPoints.Branches.Count != 0) { foreach (GH_Point pt in AllPoints[i]) { unroll.AddFollowingGeometry(pt.Value); } } unroll.ExplodeOutput = false; Curve[] curves; Point3d[] unrolledPoints; TextDot[] dots; Brep[] unrolledBreps = unroll.PerformUnroll(out curves, out unrolledPoints, out dots); if (Reorient == false) { foreach (Brep b in unrolledBreps) { AllUnrolledBreps.Add(b, originalPath); } foreach (Point3d p in unrolledPoints) { AllUnrolledPoints.Add(p, originalPath); } } else { foreach (Brep b in unrolledBreps) { AllUnrolledBreps.Add(b, pth.AppendElement(stripecounter)); } } // For reorientation if (Reorient == true) { ForReorientBreps.Add(unrolledBreps[Seam], pth); } stripecounter++; } } #endregion unroll if (Reorient == true) { //ForReorientBreps.Branch(0)[0].Curves3D[0].PointAtEnd; for (int i = 0; i < ForReorientBreps.BranchCount; i++) { GH_Path pth = new GH_Path(i); foreach (Curve crv0 in ForReorientBreps.Branch(i)[0].Curves3D) { foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D) { double l0 = crv0.GetLength(); double l1 = crv1.GetLength(); if (Math.Abs(l0 - l1) < 0.00001) { // orient crv0 Plane origin0 = new Plane(new Point3d(0, 0, 0), new Vector3d(1, 0, 0), new Vector3d(0, 1, 0)); Plane target0 = new Plane(origin0); AllOrientPlanes.Add(origin0, pth.AppendElement(0)); AllOrientPlanes.Add(target0, pth.AppendElement(0)); // orient crv1 Vector3d vect0 = crv1.TangentAtStart; Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0)); Plane origin1 = new Plane(crv1.PointAtStart, vect0, vect1); Vector3d vect2 = new Vector3d(); Vector3d vect3 = new Vector3d(); Plane target1 = new Plane(); if (Switch == true) { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0)); target1 = new Plane(crv0.PointAtStart, vect2, vect3); } else { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0)); target1 = new Plane(crv0.PointAtEnd, -vect2, vect3); } AllOrientPlanes.Add(origin1, pth.AppendElement(1)); AllOrientPlanes.Add(target1, pth.AppendElement(1)); // shared curve of stripe0 and stripe 1 AllSharedCurves.Add(crv0, pth.AppendElement(0)); AllSharedCurves.Add(crv1, pth.AppendElement(0)); } } // orient crv2 foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D) { double l0 = crv0.GetLength(); double l1 = crv2.GetLength(); if (Math.Abs(l0 - l1) < 0.00001) { Vector3d vect0 = crv2.TangentAtStart; Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0)); Plane origin2 = new Plane(crv2.PointAtStart, vect0, vect1); Vector3d vect2 = new Vector3d(); Vector3d vect3 = new Vector3d(); Plane target2 = new Plane(); if (Switch == true) { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0)); target2 = new Plane(crv0.PointAtStart, vect2, vect3); } else { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0)); target2 = new Plane(crv0.PointAtEnd, -vect2, vect3); } AllOrientPlanes.Add(origin2, pth.AppendElement(2)); AllOrientPlanes.Add(target2, pth.AppendElement(2)); // shared curve of stripe0 and stripe 2 AllSharedCurves.Add(crv2, pth.AppendElement(2)); AllSharedCurves.Add(crv0, pth.AppendElement(2)); } } } // find the shared curve oft stripe 1 and stripe 2 foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D) { foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D) { double l1 = crv1.GetLength(); double l2 = crv2.GetLength(); // shared curve of stripe1 and stripe 2 if (Math.Abs(l1 - l2) < 0.00001) { AllSharedCurves.Add(crv1, pth.AppendElement(1)); AllSharedCurves.Add(crv2, pth.AppendElement(1)); } } } } } //---- End Functions -------------------------------------------------------------------------- //----Set Output------------------------------------------------------------------------------- DA.SetDataTree(0, AllUnrolledBreps); DA.SetDataTree(1, AllOrientPlanes); DA.SetDataTree(2, AllSharedCurves); DA.SetDataTree(3, AllUnrolledPoints); //----End Set Output--------------------------------------------------------------------------- }