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])); }
public bool ParseLine(string text, ObjModel model) { Match match = Regex.Match(text, Match); if (!match.Success) { return(false); } Add(match, model); return(true); }
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)); }
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())); }
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); }
protected abstract void Add(Match match, ObjModel model);