public void TerainConvert() { BrushList bry = new BrushList(); XmlDocument document = new XmlDocument(); document.Load(fileNames); XmlNodeList nodeList = document.GetElementsByTagName("data"); foreach (XmlNode xmlnode in nodeList) { if (File.Exists("levels\\" + xmlnode.InnerText + "\\terrain\\land_map.h32")) { FileStream fso = new FileStream("levels\\" + xmlnode.InnerText + "\\terrain\\land_map.h32", FileMode.Open, FileAccess.Read); BinaryReader fds = new BinaryReader(fso); FileStream fs = new FileStream(xmlnode.Attributes["id"].InnerText + ".geo", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter fda = new BinaryWriter(fs); byte yyt = 1; int yyr = Convert.ToInt32(fso.Length / 3); fda.Write(yyt); fda.Write(yyr); int i; for (i = 0; fso.Length / 3 > i; i++) { fda.Write(fds.ReadInt16()); fds.ReadByte(); } fda.Close(); } else { FileStream fs = new FileStream(xmlnode.Attributes["id"].InnerText + ".geo", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter fda = new BinaryWriter(fs); byte yyt = 1; fda.Write(yyt); fda.Write(yyt); fda.Write(yyt); fda.Close(); } bry.Brush(xmlnode.Attributes["id"].InnerText, xmlnode.InnerText); Console.WriteLine("OK- " + xmlnode.Attributes["id"].InnerText); Console.WriteLine(bry.name_model.Count); } foreach (string name in bry.name_model) { MeshsGeo ghd = new MeshsGeo(); Meshs rtry = new Meshs(); if (File.Exists(name.Replace(".cgf", ".mesh"))) { rtry.ReadMeshs(name); } else { ghd.ComMeshs(name); } Console.WriteLine("OK"); } }
public void ReadMeshs(string path) { MeshsGeo mes = new MeshsGeo(); FileStream meshs = new FileStream("meshs.geo", FileMode.Append, FileAccess.Write); BinaryWriter meshsgeo = new BinaryWriter(meshs); List <Vector3> vertex = new List <Vector3>(); List <MeshFace> faces = new List <MeshFace>(); StreamReader sr = new StreamReader(path.Replace(".cgf", ".mesh")); string line; int cor = 0; bool cors = false; meshsgeo.Write(Convert.ToInt16(path.Length)); meshsgeo.Write(Encoding.Default.GetBytes(path)); meshsgeo.Write(Convert.ToInt16(setMeshFile(path))); while (!sr.EndOfStream) { Vector3 vector = new Vector3(); MeshFace meshfa = new MeshFace(); line = sr.ReadLine(); int inde = line.IndexOf("("); int inder = line.IndexOf(")"); if (inde != -1 && inder != -1) { if (cors == false) { cor++; cors = true; } string got = line.Substring(inde + 1, inder - 1); int xind = got.IndexOf(","); string gotx = got.Substring(0, xind); if (cor == 1) { vector.x = Single.Parse(gotx.Replace(".", ",")); } if (cor == 3) { meshfa.v0 = Convert.ToInt32(gotx); } /////////////////////////////X string goty = got.Substring(xind + 1); int yind = goty.IndexOf(","); string gotyy = goty.Substring(0, yind); if (cor == 1) { vector.y = Single.Parse(gotyy.Replace(".", ",")); } if (cor == 3) { meshfa.v1 = Convert.ToInt32(gotyy); } /////////////////////////////y string gotz = goty.Substring(yind + 1); if (cor == 1) { vector.z = Single.Parse(gotz.Replace(".", ",")); } if (cor == 3) { meshfa.v2 = Convert.ToInt32(gotz); } //////////////////////////////z if (cor == 1) { vertex.Add(vector); } if (cor == 3) { faces.Add(meshfa); } //Console.WriteLine(got + "/"+ cor); } else { cors = false; if (cor == 3) { cor = 0; meshsgeo.Write(Convert.ToInt16(vertex.Count)); for (int i = 0; vertex.Count > i; i++) { meshsgeo.Write(Convert.ToSingle(vertex[i].x / 100.0)); meshsgeo.Write(Convert.ToSingle(vertex[i].y / 100.0)); meshsgeo.Write(Convert.ToSingle(vertex[i].z / 100.0)); } meshsgeo.Write(Convert.ToInt32(faces.Count * 3)); for (int i = 0; faces.Count > i; i++) { meshsgeo.Write(Convert.ToInt16(faces[i].v0)); meshsgeo.Write(Convert.ToInt16(faces[i].v1)); meshsgeo.Write(Convert.ToInt16(faces[i].v2)); } meshsgeo.Write(Convert.ToInt16(2309)); vertex.Clear(); faces.Clear(); //return; } } } cors = false; if (cor == 3) { cor = 0; meshsgeo.Write(Convert.ToInt16(vertex.Count)); for (int i = 0; vertex.Count > i; i++) { meshsgeo.Write(Convert.ToSingle(vertex[i].x / 100.0)); meshsgeo.Write(Convert.ToSingle(vertex[i].y / 100.0)); meshsgeo.Write(Convert.ToSingle(vertex[i].z / 100.0)); } meshsgeo.Write(Convert.ToInt32(faces.Count * 3)); for (int i = 0; faces.Count > i; i++) { meshsgeo.Write(Convert.ToInt16(faces[i].v0)); meshsgeo.Write(Convert.ToInt16(faces[i].v1)); meshsgeo.Write(Convert.ToInt16(faces[i].v2)); } meshsgeo.Write(Convert.ToInt16(2309)); vertex.Clear(); faces.Clear(); //return; } sr.Close(); meshsgeo.Close(); }