Exemple #1
0
        public static ModelVertex[] ReadModelFile(Stream stream)
        {
            StreamReader r = new StreamReader(stream);
            int          ch;

            ch = r.Read();
            while (ch != ':')
            {
                ch = r.Read();
            }

            var n   = Int32.Parse(r.ReadLine());
            var ret = new ModelVertex[n];

            ch = r.Read();
            while (ch != ':')
            {
                ch = r.Read();
            }
            r.ReadLine();

            for (int i = 0; i < n; ++i)
            {
                var line = r.ReadLine().Trim();
                if (line.Length == 0)
                {
                    i -= 1;
                    continue;
                }
                var v = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(num => Single.Parse(num)).ToArray();
                ret[i].Position.X     = v[0];
                ret[i].Position.Y     = v[1];
                ret[i].Position.Z     = v[2];
                ret[i].TexutreCoord.X = v[3];
                ret[i].TexutreCoord.Y = v[4];
                ret[i].Normal.X       = v[5];
                ret[i].Normal.Y       = v[6];
                ret[i].Normal.Z       = v[7];
            }

            for (int i = 0; i < n; i += 3)
            {
                CalculateVectors(ret, i);
            }

            return(ret);
        }
Exemple #2
0
 private static void UpdateVectors(ref ModelVertex vertex, Vector3 t, Vector3 b, Vector3 n)
 {
     vertex.Tangent  = t;
     vertex.Binormal = b;
     vertex.Normal   = n;
 }