Exemplo n.º 1
0
        private IEnumerable <Facet> ReadASCII(Stream stream)
        {
            stream.Position = 0;
            Vect3 normal             = null;
            var   vertices           = new Vect3[3];
            var   i                  = 0;
            const NumberStyles style = NumberStyles.AllowExponent | NumberStyles.AllowLeadingSign | NumberStyles.Number;

            using (var reader = new StreamReader(stream))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var split = line.Trim().Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                    switch (split[0].ToLower())
                    {
                    case "solid":
                        if (split.Length > 1)
                        {
                            Header = split[1];
                        }
                        break;

                    case "facet":
                        normal = new Vect3(float.Parse(split[2], style), float.Parse(split[3], style), float.Parse(split[4], style));
                        break;

                    case "outer":
                        break;

                    case "vertex":
                        vertices[i++] = new Vect3(float.Parse(split[1], style), float.Parse(split[2], style), float.Parse(split[3], style));
                        break;

                    case "endloop":
                        break;

                    case "endfacet":
                        if (normal != null && vertices.All(v => v != null))
                        {
                            yield return(new Facet(normal, vertices[0], vertices[1], vertices[2]));
                        }
                        i = 0;
                        break;

                    case "endsolid":
                        break;
                    }
                }
            }
        }