Example #1
0
 private void SetVertex3(int value)
 {
     vertex3 = value * -1 - 1;
     triangles.Add(new Triangle(vertex1, vertex2, vertex3));
     nextVertex = SetVertex1;
 }
Example #2
0
 private void SetVertex1(int value)
 {
     vertex1    = value;
     nextVertex = SetVertex2;
 }
Example #3
0
 private void SetVertex2(int value)
 {
     vertex2    = value;
     nextVertex = SetVertex3;
 }
Example #4
0
        public WorldObject Import(string fileName)
        {
            //try
            //{
            if (fileName != null)
            {
                minX = float.MaxValue;
                maxX = float.MinValue;
                minY = float.MaxValue;
                maxY = float.MinValue;
                using (StreamReader sr = new StreamReader(fileName))
                {
                    while (!sr.EndOfStream)
                    {
                        String line = sr.ReadLine();
                        if (line.Contains("; Object connections"))
                        {
                            break;
                        }
                        if (line.Contains("Vertices:"))
                        {
                            nextSet = SetX;
                            line    = sr.ReadLine();
                            line    = line.Split(':')[1];
                            do
                            {
                                String[] linePoints = line.Split(',');
                                for (int i = 0; i < linePoints.Length; i++)
                                {
                                    if (linePoints[i].Length > 0)
                                    {
                                        nextSet(float.Parse(linePoints[i].Replace('.', ',')));
                                    }
                                }
                            }while ((line = sr.ReadLine()).Contains("}") == false);
                        }

                        if (line.Contains("PolygonVertexIndex:"))
                        {
                            nextVertex = SetVertex1;
                            line       = sr.ReadLine();
                            line       = line.Split(':')[1];
                            do
                            {
                                String[] lineTriangles = line.Split(',');
                                for (int i = 0; i < lineTriangles.Length; i++)
                                {
                                    if (lineTriangles[i].Length > 0)
                                    {
                                        nextVertex(Convert.ToInt16(lineTriangles[i]));
                                    }
                                }
                            }while ((line = sr.ReadLine()).Contains("}") == false);
                        }

                        if (line.Contains("LayerElementUV:"))
                        {
                            line = sr.ReadLine();
                            while (!line.Contains("UV:"))
                            {
                                line = sr.ReadLine();
                            }

                            nextUV = SetUV1;
                            line   = sr.ReadLine();
                            line   = line.Split(':')[1];
                            do
                            {
                                String[] lineUVs = line.Split(',');
                                for (int i = 0; i < lineUVs.Length; i++)
                                {
                                    if (lineUVs[i].Length > 0)
                                    {
                                        nextUV(float.Parse(lineUVs[i].Replace('.', ',')));
                                    }
                                }
                            }while ((line = sr.ReadLine()).Contains("}") == false);
                        }

                        if (line.Contains("Materials: "))
                        {
                            line = sr.ReadLine();
                            line = line.Split(':')[1];
                            int count = 0;
                            do
                            {
                                String[] lineTriangles = line.Split(',');
                                for (int i = 0; i < lineTriangles.Length; i++)
                                {
                                    if (lineTriangles[i].Length > 0)
                                    {
                                        triangles[count++].TextureIndex = Convert.ToInt32(lineTriangles[i]);
                                    }
                                }
                            }while ((line = sr.ReadLine()).Contains("}") == false);
                        }

                        if (line.Contains("Texture::Map"))
                        {
                            line = sr.ReadLine();
                            while (!line.Contains("FileName: "))
                            {
                                line = sr.ReadLine();
                            }

                            String texturePath = line.Substring(line.IndexOf(": ") + 3);
                            texturePath = texturePath.Remove(texturePath.Length - 1);
                            textures.Add(texturePath);
                        }
                    }
                }
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine("The file could not be read:");
                //    Console.WriteLine(e.Message);
                //}

                float height = maxY - minY;
                float width  = maxX - minX;

                return(new WorldObject(vertices, triangles, uvs, textures));
            }

            return(null);
        }