コード例 #1
0
ファイル: ModelClass.cs プロジェクト: Mexahoid/CSF
        public void Parse(string Input)
        {
            double X, Y, Z;
              string[] Arr = Input.Split(new string[] { "\n\r", "\n" }, StringSplitOptions.None);
              int Length = Arr.Length;
              string[] Row;
              bool flag = true;
              int FType = 1;  //1 - _ 2 - _/_ 3 - _/_/_ 4 - _//_
              for (int i = 0; i < Length; i++)
              {
            if (Arr[i] != "" && Arr[i][0] != '#')
              switch (Arr[i].Substring(0, 2))
              {
            case "v ":
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              Array.Resize(ref points, ++pointsLength);
              X = double.Parse(Row[1], System.Globalization.CultureInfo.InvariantCulture);
              Y = double.Parse(Row[2], System.Globalization.CultureInfo.InvariantCulture);
              Z = double.Parse(Row[3], System.Globalization.CultureInfo.InvariantCulture);
              points[pointsLength - 1] = new Structures.MyPoint(X, Y, Z);
              break;
            case "vn":
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              X = double.Parse(Row[1], System.Globalization.CultureInfo.InvariantCulture);
              Y = double.Parse(Row[2], System.Globalization.CultureInfo.InvariantCulture);
              Z = double.Parse(Row[3], System.Globalization.CultureInfo.InvariantCulture);
              Array.Resize(ref normals, ++normLength);
              normals[normLength - 1] = new Structures.MyPoint(X, Y, Z);
              break;
            case "f ":
              if (flag)
              {
                if (Arr[i].IndexOf('/') != -1)
                {
                string[] tmp = Arr[i].Split(' ');
                int Leng = tmp[1].Length;

                tmp = tmp[1].Split('/');

                  if (tmp[1][0] != '/')
                    FType = tmp.Length;
                  else
                    FType = 4;
                }
                else
                  FType = 5;
                flag = false;
              }
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              int RowLength = Row.Length - 1;
              string[] Temp;
              int[] F = new int[Row.Length - 1];
              int[] N = new int[Row.Length - 1];
              switch (FType)
              {
                case 1:
                  for (int k = 1; k <= RowLength; k++)
                    F[k - 1] = int.Parse(Row[k]);
                  break;
                case 2:
                  for (int k = 1; k <= RowLength; k++)
                  {
                    Temp = Row[k].Split('/');
                    F[k - 1] = int.Parse(Temp[0]);
                    //Здесь воткнуть массив для текстуры
                  }
                  break;
                case 3:
                  for (int k = 1; k <= RowLength; k++)
                  {
                    Temp = Row[k].Split('/');
                    F[k - 1] = int.Parse(Temp[0]);
                    //Здесь воткнуть массив для текстуры
                    N[k - 1] = int.Parse(Temp[2]);
                  }
                  break;
                case 4:
                  //Кек
                  break;
                case 5:
                  for (int k = 1; k <= RowLength; k++)
                    F[k - 1] = int.Parse(Row[k]);
                  break;
              }
              Array.Resize(ref polygons, ++polygonLength);
              if (RowLength == 3)
                polygons[polygonLength - 1] = new Structures.MyPolygon(F[0], F[1], F[2]);
              else
                polygons[polygonLength - 1] = new Structures.MyPolygon(F[0], F[1], F[2], F[3]);

              switch (FType)
              {
                case 4:
                  Array.Resize(ref edges, edgeLength + 4);
                  edgeLength += 4;
                  edges[edgeLength - 4] = new Structures.MyEdge(F[0], F[1]);
                  edges[edgeLength - 3] = new Structures.MyEdge(F[1], F[2]);
                  edges[edgeLength - 2] = new Structures.MyEdge(F[2], F[3]);
                  edges[edgeLength - 1] = new Structures.MyEdge(F[3], F[0]);
                  break;
                default:
                  Array.Resize(ref edges, edgeLength + 3);
                  edgeLength += 3;
                  edges[edgeLength - 3] = new Structures.MyEdge(F[0], F[1]);
                  edges[edgeLength - 2] = new Structures.MyEdge(F[1], F[2]);
                  edges[edgeLength - 1] = new Structures.MyEdge(F[2], F[0]);
                  break;
              }
              break;
              }
              }
              _GetVectorNormals();
        }
コード例 #2
0
ファイル: ModelClass.cs プロジェクト: Mexahoid/CSF
        public void Parse(string Input)
        {
            double AllX = 0, AllY = 0, AllZ = 0;
              double X, Y, Z;
              string[] Arr = Input.Split(new string[] { "\n\r", "\n" }, StringSplitOptions.None);
              int Length = Arr.Length;
              string[] Row;
              bool flag = true;
              int FType = 1;  //1 - _ 2 - _/_ 3 - _/_/_ 4 - _//_
              for (int i = 0; i < Length; i++)
              {
            if (Arr[i] != "" && Arr[i][0] != '#')
              switch (Arr[i].Substring(0, 2))
              {
            case "v ":
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              Array.Resize(ref Points, ++PLength);
              X = double.Parse(Row[1], System.Globalization.CultureInfo.InvariantCulture);
              Y = double.Parse(Row[2], System.Globalization.CultureInfo.InvariantCulture);
              Z = double.Parse(Row[3], System.Globalization.CultureInfo.InvariantCulture);
              AllX += X;
              AllY += Y;
              AllZ += Z;
              Points[PLength - 1] = new Structures.MyPoint(X, Y, Z);
              break;
            case "vn":
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              X = double.Parse(Row[1], System.Globalization.CultureInfo.InvariantCulture);
              Y = double.Parse(Row[2], System.Globalization.CultureInfo.InvariantCulture);
              Z = double.Parse(Row[3], System.Globalization.CultureInfo.InvariantCulture);
              Array.Resize(ref Normals, ++NLength);
              Normals[NLength - 1] = new Structures.MyPoint(X, Y, Z);
              break;
            case "f ":
              if (flag)
              {
                string[] tmp = Arr[i].Split(' ');
                int Leng = tmp[1].Length;
                tmp = tmp[1].Split('/');
                if (tmp[1][0] != '/')
                  FType = tmp.Length;
                else
                  FType = 4;
                flag = false;
              }
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              int RowLength = Row.Length - 1;
              string[] Temp;
              int[] F = new int[Row.Length - 1];
              int[] N = new int[Row.Length - 1];
              switch (FType)
              {
                case 1:
                  for (int k = 1; k <= RowLength; k++)
                    F[k - 1] = int.Parse(Row[k]);
                  break;
                case 2:
                  for (int k = 1; k <= RowLength; k++)
                  {
                    Temp = Row[k].Split('/');
                    F[k - 1] = int.Parse(Temp[0]);
                    //Здесь воткнуть массив для текстуры
                  }
                  break;
                case 3:
                  for (int k = 1; k <= RowLength; k++)
                  {
                    Temp = Row[k].Split('/');
                    F[k - 1] = int.Parse(Temp[0]);
                    //Здесь воткнуть массив для текстуры
                    N[k - 1] = int.Parse(Temp[2]);
                  }
                  break;
                case 4:
                  //Кек
                  break;
              }
              Array.Resize(ref Polygons, ++RLength);
              if (RowLength == 3)
                Polygons[RLength - 1] = new Structures.MyPolygon(F[0], F[1], F[2]);
              else
                Polygons[RLength - 1] = new Structures.MyPolygon(F[0], F[1], F[2], F[3]);

              if (FType > 2)
              {
                Polygons[RLength - 1].NF = N[0];
                Polygons[RLength - 1].NS = N[1];
                Polygons[RLength - 1].NT = N[2];
                if (FType == 4)
                  Polygons[RLength - 1].NFr = N[3];
              }
              switch (FType)
              {

                case 4:
                  Array.Resize(ref Edges, ELength + 4);
                  ELength += 4;
                  Edges[ELength - 4] = new Structures.MyEdge(F[0], F[1]);
                  Edges[ELength - 3] = new Structures.MyEdge(F[1], F[2]);
                  Edges[ELength - 2] = new Structures.MyEdge(F[2], F[3]);
                  Edges[ELength - 1] = new Structures.MyEdge(F[3], F[0]);
                  break;
                default:
                  Array.Resize(ref Edges, ELength + 3);
                  ELength += 3;
                  Edges[ELength - 3] = new Structures.MyEdge(F[0], F[1]);
                  Edges[ELength - 2] = new Structures.MyEdge(F[1], F[2]);
                  Edges[ELength - 1] = new Structures.MyEdge(F[2], F[0]);
                  break;
              }
              break;
              }
              }
              GetVectorNormals();
              Center = new Structures.MyPoint(AllX / PLength, AllY / PLength, AllZ / PLength);
        }