Beispiel #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh m = new Mesh();

            DA.GetData(0, ref m);
            int i = 0;

            DA.GetData(1, ref i);
            int iterations = 0;

            DA.GetData(2, ref iterations);

            if (m.IsValid)
            {
                List <List <int> > nakedVertices  = m.GetNakedVerticesID(iterations);
                List <Polyline>    nakedPolylines = m.GetNakedPolylines(nakedVertices);
                Mesh mesh = m.DuplicateMesh();


                if (nakedVertices.Count != 0)
                {
                    int check = mesh.Ngons.AddNgon(MeshNgon.Create(nakedVertices[i.Wrap(nakedVertices.Count)], Enumerable.Range(0, m.Faces.Count).ToList()));
                    PreparePreview(mesh, DA.Iteration, nakedPolylines);
                    DA.SetData(0, mesh);
                    DA.SetDataTree(1, GrasshopperUtil.IE2(nakedVertices, DA.Iteration));
                    DA.SetDataTree(2, GrasshopperUtil.IE(nakedPolylines, DA.Iteration));
                }
                else
                {
                    DA.SetData(0, m);
                    DA.SetDataTree(1, new Grasshopper.DataTree <int>());
                    DA.SetDataTree(2, new Grasshopper.DataTree <Polyline>());
                }
            }
            else
            {
                DA.SetData(0, m);
                DA.SetDataTree(1, new Grasshopper.DataTree <int>());
                DA.SetDataTree(2, new Grasshopper.DataTree <Polyline>());
            }
        }
Beispiel #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh m = new Mesh();

            DA.GetData(0, ref m);

            double dist = DA.Fetch <double>("Offset");
            bool   flip = DA.Fetch <bool>("Flip");

            if (dist != 0)
            {
                m = m.FaceFaceOffset(dist);
                //Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(m);
            }

            Mesh M = NGonsCore.MeshCreate.MeshFromPolylines(m.GetFacePolylinesArray(), 0.01);

            if (flip)
            {
                M.Flip(true, true, true);
            }
            DA.SetData(4, M);

            try
            {
                MeshProps mp = M._Planes();



                DA.SetData(0, mp);
                DA.SetDataTree(1, GrasshopperUtil.IE(mp.fPl, -1));
                DA.SetDataTree(2, GrasshopperUtil.IE2(mp.fePl));
                // DA.SetDataTree(3, GrasshopperUtil.IE2(mp.fePl90));
                DA.SetDataTree(3, GrasshopperUtil.IE(mp.ePl));
                //DA.SetDataTree(5, GrasshopperUtil.IE(mp.ePl90));
            }
            catch (Exception e)
            {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
        }
Beispiel #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh        mesh          = DA.Fetch <Mesh>("Mesh");
            string      v             = DA.Fetch <string>("Start");
            List <int>  o             = DA.FetchList <int>("Sequence");
            Curve       sequenceCrv   = DA.Fetch <Curve>("SequenceCrv");
            List <Line> customVectors = DA.FetchList <Line>("CustomVectors");
            double      angleTol      = DA.Fetch <double>("Angle");



            v = Math.Min(Convert.ToInt32(v), mesh.Ngons.Count - 1).ToString();



            if (mesh.Ngons.Count == o.Count)
            {
                mesh         = mesh.ReoderMeshNgons(o);
                base.Message = "Sequence";
            }
            else if (sequenceCrv != null)
            {
                if (sequenceCrv.IsValid)
                {
                    mesh = mesh.ReoderMeshNgons(sequenceCrv);
                    List <int> order = Enumerable.Range(0, mesh.Ngons.Count).ToList();
                    base.Message = "Sequence Curve";
                }
            }
            else
            {
                var        ve    = NGonsCore.Graphs.UndirectedGraphBfsRhino.MeshBFS(mesh, v);
                List <int> order = ve.Item1[0];
                mesh         = mesh.ReoderMeshNgons(ve.Item1[0]);
                base.Message = "BFS";
                DA.SetDataTree(0, GrasshopperUtil.IE2(ve.Item1));
                DA.SetDataTree(1, GrasshopperUtil.IE3(ve.Item2));
            }

            DA.SetData(4, mesh);


            List <int> order_ = Enumerable.Range(0, mesh.Ngons.Count).ToList();

            DataTree <int> vertices_ = new DataTree <int>(order_);
            DataTree <int> edges_    = new DataTree <int>();

            for (int i = 0; i < order_.Count - 1; i++)
            {
                edges_.Add(order_[i], new GH_Path(i));
                edges_.Add(order_[i] + 1, new GH_Path(i));
            }


            int S = mesh.Ngons.Count;//stop
            //Insertion vectors
            DataTree <int> N = SequenceNeighbours(mesh, order_, S);

            //FN = N;
            //O_ = O;
            //Edge Vectors
            int[][]                 tv     = mesh.GetNGonsTopoBoundaries();
            int[][]                 fe     = mesh.GetNGonFacesEdges(tv);
            HashSet <int>           e      = mesh.GetAllNGonEdges(tv);
            Dictionary <int, int[]> efDict = mesh.GetFE(e, false);

            Polyline[] outlines = mesh.GetPolylines();



            //Dictionary<int, Vector3d> edgeVectors = new Dictionary<int, Vector3d> ();
            DataTree <Vector3d> edgeVectors = new DataTree <Vector3d>();
            List <Vector3d>     faceVectors = new List <Vector3d>();
            Dictionary <int, List <GH_Path> > faceEdgeID = new Dictionary <int, List <GH_Path> >();


            for (int i = 0; (i < S && i < mesh.Ngons.Count); i++)
            {
                /////////////
                // Properties
                /////////////
                //Current path and face
                GH_Path p = new GH_Path(i);
                int     f = order_[i];//O[i];
                if (!N.PathExists(p))
                {
                    continue;                                        //If no connectio nskip
                }
                HashSet <int> fadj = new HashSet <int>(N.Branch(p)); //adjacency list


                /////////////
                // Solution
                /////////////
                //Iterate mesh edges
                //Get connected faces
                //Check if they are in adjacency list
                //The order thoses ids

                List <int> NotOrderedEdges = new List <int>();
                for (int j = 0; j < fe[f].Length; j++)
                {
                    int[] facePair = efDict[fe[f][j]];//get face pair
                    if (facePair.Length == 1)
                    {
                        continue;                      //if naked skip
                    }
                    if (fadj.Contains(facePair[0]) || fadj.Contains(facePair[1]))
                    {
                        NotOrderedEdges.Add(j);                                                          //if edge face are in fadj
                    }
                }

                List <int> orderedEdges = SortIntegers(NotOrderedEdges, fe[f].Length);


                //Collect lines for Insertion Vector
                List <Line> el = new List <Line>();
                //Line[] lines = outlines[f].GetSegments();
                foreach (int j in orderedEdges)
                {
                    el.Add(outlines[f].SegmentAt(j));//el.Add(M.TopologyEdges.EdgeLine(fe[f][j]));
                }

                //Create Insertion Vector
                Vector3d vec = NGonsCore.VectorUtil.BisectorVector(el, outlines[f].AverageNormal(), false);
                faceVectors.Add(vec);


                List <GH_Path> paths = new List <GH_Path>();
                foreach (int j in orderedEdges)
                {
                    //edgeVectors.Add(fe[f][j],vec);
                    edgeVectors.Add(vec, new GH_Path(fe[f][j]));
                    paths.Add(new GH_Path(fe[f][j]));
                }

                faceEdgeID.Add(i, paths);
                //Rhino.RhinoApp.WriteLine(i.ToString() + " " + paths.Count.ToString());

                //A = el;
                //B = vec;
                //C = outlines[f].AverageNormal();
            }

            DataTree <Vector3d> EV    = mesh.insertionVectors(true);
            DataTree <Line>     edges = new DataTree <Line>();
            PointCloud          cloud = new PointCloud();

            //Check angles if vectors are not parallel to mesh edge
            foreach (GH_Path p in EV.Paths)
            {
                Line  line      = mesh.TopologyEdges.EdgeLine(p.Indices[0]);
                Plane edgePlane = new Plane(line.PointAt(0.5), mesh.GetMeshEdgePerpDir(p.Indices[0]));

                cloud.Add(line.PointAt(0.5), new Vector3d(p.Indices[0], 0, 0));

                double angledifference = Math.Abs(Vector3d.VectorAngle(line.Direction, edgeVectors.Branch(p)[0], edgePlane) % Math.PI);

                //Rhino.RhinoApp.WriteLine(angledifference.ToString());
                if (angledifference < angleTol || angledifference > (Math.PI - angleTol))
                {
                    edges.Add(new Line(line.PointAt(0.5), line.PointAt(0.5) + line.Direction.UnitVector() * line.Length * 0.25), p);
                    edges.Add(new Line(line.PointAt(0.5), line.PointAt(0.5) + edgeVectors.Branch(p)[0].UnitVector() * line.Length * 0.25), p);
                    edgeVectors.Branch(p)[0] = -EV.Branch(p)[0];
                }
                else
                {
                }
            }


            //Change insertion vectors
            if (customVectors.Count > 0)
            {
                for (int i = 0; i < customVectors.Count; i++)
                {
                    int edgeID = cloud.ClosestPoint(customVectors[i].From);
                    edgeVectors.Branch(new GH_Path((int)cloud[edgeID].Normal.X))[0] = customVectors[i].Direction;
                }
            }

            //Rhino.RhinoApp.WriteLine (faceEdgeID.Count.ToString());

            List <Vector3d> NGonsVectors = new List <Vector3d>()
            {
                Vector3d.ZAxis
            };

            for (int i = 1; i < faceEdgeID.Count; i++)
            {
                Vector3d vec = Vector3d.Zero;
                for (int j = 0; j < faceEdgeID[i].Count; j++)
                {
                    vec += edgeVectors.Branch(faceEdgeID[i][j])[0];
                }
                vec.Unitize();
                NGonsVectors.Add(vec);
            }

            DA.SetDataList(5, NGonsVectors);

            //EV = edgeVectors;
            DA.SetDataTree(2, edgeVectors);
            DA.SetDataTree(3, edges);
            //Get current face edges
            //Take edge only connected in current set
        }