public static ITurtleMesh ImportRhinoMesh(Mesh m)
        {
            var t = new TurtleMesh();

            var mv = m.Vertices;

            for (int i = 0; i < mv.Count; i++)
            {
                var v = mv[i];
                t.AddVertex(new TurtleVertex(v.X, v.Y, v.Z));
            }

            var mf = m.Faces;

            for (int i = 0; i < mf.Count; i++)
            {
                var f = mf[i];
                if (f.IsTriangle)
                {
                    t.AddFace(new TurtleFace(f.A, f.B, f.C));
                }
                else
                {
                    t.AddFace(new TurtleFace(f.A, f.B, f.C, f.D));
                }
            }

            return(t);
        }
        public static TurtleMesh ExtractTMesh(Curve c)
        {
            var      m = new TurtleMesh();
            Polyline pl;

            c.TryGetPolyline(out pl);

            TurtleFace f = new TurtleFace(pl.Count - 1);

            for (int j = 0; j < pl.Count - 1; j++)
            {
                var v = pl[j];
                f.Add(m.VertexCount);
                m.AddVertex(new TurtleVertex((float)v.X, (float)v.Y, (float)v.Z));
            }
            m.AddFace(f);
            return(m);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var list = new List <ITurtleMesh>();

            if (DA.GetDataList(0, list))
            {
                var nm = new TurtleMesh();

                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] != null)
                    {
                        nm.AppendOther(list[i]);
                    }
                }

                DA.SetData(0, nm);
            }
        }
Example #4
0
        public override IGH_GeometricGoo Morph(Rhino.Geometry.SpaceMorph xmorph)
        {
            if (m_value != null)
            {
                var m = new TurtleMesh(m_value);

                foreach (var v in m.GetVerticesEnumerable())
                {
                    Point3d p = new Point3d(v.X, v.Y, v.Z);
                    p = xmorph.MorphPoint(p);

                    v.X = (float)p.X;
                    v.Y = (float)p.Y;
                    v.Z = (float)p.Z;
                }

                return(new GH_TurtleMesh(m));
            }
            else
            {
                return(new GH_TurtleMesh(null));
            }
        }
Example #5
0
        public override IGH_GeometricGoo Transform(Rhino.Geometry.Transform xform)
        {
            if (m_value != null)
            {
                var m = new TurtleMesh(m_value);

                foreach (var v in m.GetVerticesEnumerable())
                {
                    Point3f p = new Point3f(v.X, v.Y, v.Z);
                    p.Transform(xform);

                    v.X = p.X;
                    v.Y = p.Y;
                    v.Z = p.Z;
                }

                return(new GH_TurtleMesh(m));
            }
            else
            {
                return(new GH_TurtleMesh(null));
            }
        }
        public static ITurtleMesh Read(TextReader sr)
        {
            TurtleMesh m = new TurtleMesh();

            var ci = System.Globalization.CultureInfo.InvariantCulture;

            int linecount = 0;

            string line;

            while ((line = sr.ReadLine()) != null)
            {
                linecount++;

                if (line.TrimStart(_separators).StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                var tokens = line.Split(_separators, StringSplitOptions.RemoveEmptyEntries);

                if (tokens.Length < 2)
                {
                    continue;
                }

                var token0 = tokens[0].ToLowerInvariant();

                if (token0 == "v")
                {
                    if (tokens.Length < 4 || tokens.Length > 5)
                    {
                        throw new ArgumentOutOfRangeException(string.Format("Line {0} contains a vertex with number of coordinates different than 3 or 4.", linecount.ToString(ci)));
                    }

                    float x;
                    if (!float.TryParse(tokens[1], System.Globalization.NumberStyles.Any, ci, out x))
                    {
                        throw new ArgumentException(string.Format("Line {0} contains an invalid X coordinate.", linecount.ToString(ci)));
                    }

                    float y;
                    if (!float.TryParse(tokens[2], System.Globalization.NumberStyles.Any, ci, out y))
                    {
                        throw new ArgumentException(string.Format("Line {0} contains an invalid Y coordinate.", linecount.ToString(ci)));
                    }

                    float z;
                    if (!float.TryParse(tokens[3], System.Globalization.NumberStyles.Any, ci, out z))
                    {
                        throw new ArgumentException(string.Format("Line {0} contains an invalid Z coordinate.", linecount.ToString(ci)));
                    }

                    TurtleVertex v = new TurtleVertex(x, y, z);
                    m.AddVertex(v);
                }
                else if (token0 == "f")
                {
                    if (tokens.Length < 3)
                    {
                        throw new ArgumentOutOfRangeException(string.Format("Line {0} contains a face with less than three indices.", linecount.ToString(ci)));
                    }

                    var f = new TurtleFace();

                    for (int i = 1; i < tokens.Length; i++)
                    {
                        int loc;
                        if (!int.TryParse(tokens[i], System.Globalization.NumberStyles.Integer, ci, out loc))
                        {
                            throw new ArgumentException(string.Format("Line {0} contains an invalid face number in token {1}.", linecount.ToString(ci), (i - 1).ToString(ci)));
                        }

                        f.Add(loc - 1);
                    }

                    m.AddFace(f);
                }
                //else texture, else normal
            }

            return(m);
        }
Example #7
0
        public static ITurtleMesh Read(TextReader sr)
        {
            TurtleMesh m = new TurtleMesh();

            var ci = System.Globalization.CultureInfo.InvariantCulture;

            int linecount = 0;

            string line;
            while ((line = sr.ReadLine()) != null)
            {
                linecount++;

                if (line.TrimStart(_separators).StartsWith("#", StringComparison.InvariantCultureIgnoreCase)) continue;

                var tokens = line.Split(_separators, StringSplitOptions.RemoveEmptyEntries);

                if (tokens.Length < 2) continue;

                var token0 = tokens[0].ToLowerInvariant();

                if (token0 == "v")
                {
                    if (tokens.Length < 4 || tokens.Length > 5)
                        throw new ArgumentOutOfRangeException(string.Format("Line {0} contains a vertex with number of coordinates different than 3 or 4.", linecount.ToString(ci)));

                    float x;
                    if(!float.TryParse(tokens[1], System.Globalization.NumberStyles.Any, ci, out x))
                        throw new ArgumentException(string.Format("Line {0} contains an invalid X coordinate.", linecount.ToString(ci)));

                    float y;
                    if (!float.TryParse(tokens[2], System.Globalization.NumberStyles.Any, ci, out y))
                        throw new ArgumentException(string.Format("Line {0} contains an invalid Y coordinate.", linecount.ToString(ci)));

                    float z;
                    if (!float.TryParse(tokens[3], System.Globalization.NumberStyles.Any, ci, out z))
                        throw new ArgumentException(string.Format("Line {0} contains an invalid Z coordinate.", linecount.ToString(ci)));

                    TurtleVertex v = new TurtleVertex(x, y, z);
                    m.AddVertex(v);
                }
                else if (token0 == "f")
                {
                    if (tokens.Length < 3)
                        throw new ArgumentOutOfRangeException(string.Format("Line {0} contains a face with less than three indices.", linecount.ToString(ci)));

                    var f = new TurtleFace();

                    for (int i = 1; i < tokens.Length; i++)
                    {
                        int loc;
                        if (!int.TryParse(tokens[i], System.Globalization.NumberStyles.Integer, ci, out loc))
                            throw new ArgumentException(string.Format("Line {0} contains an invalid face number in token {1}.", linecount.ToString(ci), (i - 1).ToString(ci)));

                        f.Add(loc - 1);
                    }

                    m.AddFace(f);
                }
                //else texture, else normal
            }

            return m;
        }