Beispiel #1
0
 public OBJFile()
 {
     this.vertices = new List<VertexPosition>();
     this.triangleFaces = new List<TriangleFace>();
     this.quadFaces = new List<QuadFace>();
     this.mesh = new MeshBase();
 }
Beispiel #2
0
 public MeshBase(MeshBase mesh)
 {
     this.name = mesh.name.Clone() as string;
     this.vertices = new List<VertexPosition>(mesh.vertices);
     this.triangleFaces = new List<TriangleFace>(mesh.triangleFaces);
     this.quadFaces = new List<QuadFace>(mesh.quadFaces);
 }
Beispiel #3
0
 public MeshBase(MeshBase mesh)
 {
     this.name          = mesh.name.Clone() as string;
     this.vertices      = new List <VertexPosition>(mesh.vertices);
     this.triangleFaces = new List <TriangleFace>(mesh.triangleFaces);
     this.quadFaces     = new List <QuadFace>(mesh.quadFaces);
 }
Beispiel #4
0
 public OBJFile(FileStream stream)
 {
     this.vertices = new List<VertexPosition>();
     this.triangleFaces = new List<TriangleFace>();
     this.quadFaces = new List<QuadFace>();
     StreamReader reader = new StreamReader(stream);
     string text = reader.ReadToEnd();
     text = text.Replace("\r", "");
     text = text.Replace('.', ',');
     string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string line in lines)
     {
         string[] words = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
         //if (words[0] == "v")
         //{
         //    float x = float.Parse(words[1]);
         //    float y = float.Parse(words[2]);
         //    float z = float.Parse(words[3]);
         //    VertexPosition coord = new VertexPosition(x, y, z);
         //    this.vertices.Add(coord);
         //}
         switch (words[0])
         {
             case "v":
                 float x = float.Parse(words[1]);
                 float y = float.Parse(words[2]);
                 float z = float.Parse(words[3]);
                 VertexPosition coord = new VertexPosition(x, y, z);
                 this.vertices.Add(coord);
                 break;
             case "f":
                 if (words.Length == 5)
                 {
                     int a4 = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     int b4 = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     int c4 = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     int d4 = int.Parse(words[4].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                     QuadFace face4 = new QuadFace(a4, b4, c4, d4);
                     this.quadFaces.Add(face4);
                     break;
                 }      
                 int a = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                 int b = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                 int c = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                 TriangleFace face = new TriangleFace(a, b, c);
                 this.triangleFaces.Add(face);
                 break;
         }
     }
     this.mesh = new MeshBase();
     this.mesh.QuadFaces = this.quadFaces;
     this.mesh.TriangleFaces = this.triangleFaces;
     this.mesh.Vertices = this.vertices;
     string[] path =  stream.Name.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
     this.mesh.Name = HeadFile.ReplaceExtention(path[path.Length - 1],"");
 }
Beispiel #5
0
        void openOBJFileButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "OBJ Files (*.obj)|*.obj|" + "Nif Files (*.nif)|*.nif|" + "All files (*.*)|*.*";
            if (open.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if(open.FileName.ToLower().EndsWith(".obj"))
                    {
                        FileStream stream = new FileStream(open.FileName, FileMode.Open);
                        OBJFile objFile = new OBJFile(stream);
                        this.reference = objFile.Mesh;
                        stream.Close();
                        this.menu.referenceTextBox.Text = open.FileName;
                        return;
                    }
                    if (open.FileName.ToLower().EndsWith(".nif"))
                    {
                        FileStream stream = new FileStream(open.FileName, FileMode.Open);
                        NifFile nifFile = new NifFile(stream);
                        this.reference = nifFile.MeshData[0];
                        stream.Close();
                        this.menu.referenceTextBox.Text = open.FileName;
                        return;
                    }
                }
                catch (Exception)
                {

                }
            }
        }