Exemplo n.º 1
0
        protected override void Add(Match match, ObjModel model)
        {
            int id1 = int.Parse(match.Groups[1].Value) - 1;
            int id2 = int.Parse(match.Groups[2].Value) - 1;

            model.Lines.Add(new Line(model.Vertices[id1], model.Vertices[id2]));
        }
Exemplo n.º 2
0
        public bool ParseLine(string text, ObjModel model)
        {
            Match match = Regex.Match(text, Match);

            if (!match.Success)
            {
                return(false);
            }

            Add(match, model);
            return(true);
        }
Exemplo n.º 3
0
        protected override void Add(Match match, ObjModel model)
        {
            double x = double.Parse(match.Groups[1].Captures[0].Value);
            double y = double.Parse(match.Groups[1].Captures[1].Value);
            double z = double.Parse(match.Groups[1].Captures[2].Value);
            double w = 0;

            if (match.Groups.Count == 8)
            {
                w = double.Parse(match.Groups[1].Captures[3].Value);
            }
            model.Vertices.Add(new Vertex(x, y, z, w));
        }
Exemplo n.º 4
0
        protected override void Add(Match match, ObjModel model)
        {
            List <Vertex> vertices = new List <Vertex>();

            foreach (Capture capture in match.Groups[2].Captures)
            {
                int index = int.Parse(capture.Value);
                if (index > 0)
                {
                    index = index - 1;
                }
                else if (index < 0)
                {
                    index = model.Vertices.Count - index;
                }
                vertices.Add(model.Vertices[index]);
            }
            model.Faces.Add(new Face(vertices.ToArray()));
        }
Exemplo n.º 5
0
        public static ObjModel Import(string obj)
        {
            string[] lines = obj.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.None
                );

            ObjModel model = new ObjModel();

            foreach (string line in lines)
            {
                foreach (ObjImportParser parser in LineParsers)
                {
                    if (parser.ParseLine(line, model))
                    {
                        break;
                    }
                }
            }

            return(model);
        }
Exemplo n.º 6
0
 protected abstract void Add(Match match, ObjModel model);