/// <summary> Loads WMO from file </summary> /// <param name="fileName">Full name of file of the WMO</param> /// <returns>Loaded WMO</returns> private static Model LoadWMO(string fileName) { var path = fileName; MOHD mohd; var fileInfo = FileInfoFactory.Create(); if (fileInfo.Exists(path) == false) { throw new Exception(String.Format("File does not exist: {0}", path)); } using (var br = new BinaryReader(fileInfo.OpenRead(path))) { int version = new MVERChunkParser(br, br.BaseStream.Position).Parse(); mohd = new MOHDChunkParser(br, br.BaseStream.Position).Parse(); } var list = new TriangleListCollection(); for (int wmoGroup = 0; wmoGroup < mohd.GroupsCount; wmoGroup++) { list.Add(LoadWMOSub(String.Format("{0}_{1:D3}.wmo", fileName.Substring(0, fileName.Length - 4), wmoGroup))); } return(new Model(list)); }
public void ExtendedFileInfoTestShortFilePath() { var shortFilePath = @"C:\FilePath\ShortPath\Textdocument.txt"; var extendedFileInfo = FileInfoFactory.Create(shortFilePath); using (var fileStream = extendedFileInfo.Open(FileMode.Open, FileAccess.Read)) { var buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); } }
public virtual List <FileInformation> Read(string path) { var listOfFiles = new List <FileInformation>(); var files = _directoryImpl.ReadDirectory(path); foreach (var file in files) { var fileInfomation = _fileInfoFactory.Create(file); listOfFiles.Add(fileInfomation); } return(listOfFiles); }
private ADT ReadADT(int x, int y) { string file = GetAdtFileName(x, y); IFileInfo fileInfo = FileInfoFactory.Create(); if (fileInfo.Exists(file) == false) { throw new Exception(String.Format("ADT Doesn't exist: {0}", file)); } using (var reader = new BinaryReader(fileInfo.OpenRead(file))) { return(new ADTChunkFileParser(reader).Parse()); } }
private static Model LoadM2(string fileName) { string path = fileName; if (path.Substring(path.Length - 4) == ".mdx") { path = path.Substring(0, path.Length - 4) + ".m2"; } var fileInfo = FileInfoFactory.Create(); if (!fileInfo.Exists(path)) { throw new Exception(String.Format("File does not exist: {0}", path)); } using (var br = new BinaryReader(fileInfo.OpenRead(path))) { br.BaseStream.Position = 60; //wotlk uint numberOfVerts = br.ReadUInt32(); uint vertsOffset = br.ReadUInt32(); uint numberOfViews = br.ReadUInt32(); //UInt32 viewsOffset = br.ReadUInt32(); //now in skins br.BaseStream.Position = 216; //wotlk uint nBoundingTriangles = br.ReadUInt32(); uint ofsBoundingTriangles = br.ReadUInt32(); uint nBoundingVertices = br.ReadUInt32(); uint ofsBoundingVertices = br.ReadUInt32(); uint nBoundingNormals = br.ReadUInt32(); uint ofsBoundingNormals = br.ReadUInt32(); var indices = new IndicesParser(br, ofsBoundingTriangles, nBoundingTriangles).Parse(); var vectors = new VectorsListParser(br, ofsBoundingVertices, nBoundingVertices).Parse(); //var normals = new VectorsListParser(br, ofsBoundingNormals, nBoundingNormals).Parse(); var vertices = vectors .Select(t => new VertexPositionNormalColored(t, Color.Red, Vector3.Up)) .ToList(); var list = new TriangleList(indices, vertices); return(new Model(list)); } }
/// <summary> /// Gets a WMO_Sub from the WMO Group file /// </summary> /// <param name="fileName">Full Filename of the WMO_Sub</param> /// <returns></returns> private static TriangleList LoadWMOSub(string fileName) { var path = fileName; var fileInfo = FileInfoFactory.Create(); if (fileInfo.Exists(path) == false) { throw new Exception(String.Format("File does not exist: {0}", path)); } using (var reader = new BinaryReader(fileInfo.OpenRead(path))) { var indices = new MOVIChunkParser(reader, FileChunkHelper.SearchChunk(reader, "MOVI").StartPosition).Parse(); var vectors = new MOVTChunkParser(reader, FileChunkHelper.SearchChunk(reader, "MOVT").StartPosition).Parse(); var normals = new MONRChunkParser(reader, FileChunkHelper.SearchChunk(reader, "MONR").StartPosition).Parse(); var vertices = new List <VertexPositionNormalColored>(); for (var i = 0; i < vectors.Count; i++) { vertices.Add(new VertexPositionNormalColored(vectors[i], Color.Yellow, normals[i])); } return(new TriangleList(indices, vertices)); } }