Example #1
0
        /// <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)
        {
            HeGraph3d graph       = null;
            double    layerHeigth = 0;
            double    length      = 0;

            if (!DA.GetData(0, ref graph))
            {
                return;
            }
            if (!DA.GetData(1, ref layerHeigth))
            {
                return;
            }
            if (!DA.GetData(2, ref length))
            {
                return;
            }

            var f       = new DataTree <Plane>();
            var tparams = new DataTree <double>();

            List <GH_Path> branches = new List <GH_Path>();

            for (int i = 0; i < graph.Edges.Count; i++)
            {
                branches.Add(new GH_Path(i));
            }

            for (int i = 0; i < graph.Vertices.Count; i++)
            {
                for (int j = 0; j < graph.Vertices[i].ConnectedVertices.ToList().Count; j++)
                {
                    var v0 = graph.Vertices[i].Position;
                    var v1 = graph.Vertices[i].ConnectedVertices.ToList()[j].Position;

                    var eVec = (v0 - v1).Unit;
                    var dist = v0.DistanceTo(v1);

                    var zUnit = new Vec3d(1, 0, 0);
                    var n     = Vec3d.Cross(eVec, zUnit).Unit;
                    var bn    = Vec3d.Cross(eVec, n).Unit;
                    var bbn   = Vec3d.Cross(eVec, bn).Unit;

                    var frames = new List <Rhino.Geometry.Plane>();
                    var edgeId = graph.Vertices[i].FindHalfedgeTo(graph.Vertices[i].ConnectedVertices.ToList()[j]).Index >> 1;

                    var branch = new GH_Path(edgeId);

                    int    cnt = 0;
                    double l   = 0;

                    do
                    {
                        Point3d pt = v0 - eVec * cnt * layerHeigth;
                        l += v0.DistanceTo((Vec3d)pt);

                        var frame = new Rhino.Geometry.Plane((Point3d)pt, (Vector3d)bn, (Vector3d)bbn);

                        frames.Add(frame);
                        cnt++;
                    }while (length > l);

                    f.AddRange(frames, branch);
                }
            }

            for (int i = 0; i < graph.Edges.Count; i++)
            {
                var count = f.Branch(i).Count;
                var t0    = 1.0 / (double)count;

                for (int j = 0; j < count; j++)
                {
                    tparams.Add((j * t0), new GH_Path(i));
                }
            }

            DA.SetDataTree(0, f);
            DA.SetDataTree(1, tparams);
        }