public TextureMapFile Load(string directory, string filename_or_filepath) { var texture_map_loader = new TextureMapLoader(); var filepath = File.Exists(filename_or_filepath) ? filename_or_filepath : directory + Path.DirectorySeparatorChar + filename_or_filepath; return(new TextureMapFile(filepath)); }
public MtlFile Load(string directory, string filename_or_filepath) { var texture_map_loader = new TextureMapLoader(); var filepath = File.Exists(filename_or_filepath) ? filename_or_filepath : directory + Path.DirectorySeparatorChar + filename_or_filepath; var stream_reader = new StreamReader(filepath); var mtl_file = new MtlFile(filepath); MtlInfo mtl_info = new MtlInfo(); while (true) { var line = stream_reader.ReadLine(); if (null == line) { break; } if (0 == line.Length) { continue; } if ('#' == line[0]) { continue; } string[] tokens = line.Split(new char[] { ' ' }, 2); if (tokens.Length < 2) { continue; } string token = tokens[0]; string content = tokens[1]; switch (token) { case "newmtl": mtl_info = new MtlInfo(content); mtl_file.Materials.Add(mtl_info.newmtl, mtl_info); break; case "Ns": mtl_info.Ns = Single.Parse(content); break; case "Ka": mtl_info.Ka = ParseFloats(content, ' '); break; case "Kd": mtl_info.Kd = ParseFloats(content, ' '); break; case "Ks": mtl_info.Ks = ParseFloats(content, ' '); break; case "Ni": mtl_info.Ni = Single.Parse(content); break; case "d": mtl_info.d = Single.Parse(content); break; case "illum": mtl_info.illum = Byte.Parse(content); break; case "map_Kd": mtl_info.map_Kd = texture_map_loader.Load(directory, content); break; case "map_Ks": mtl_info.map_Ks = texture_map_loader.Load(directory, content); break; case "map_Ka": mtl_info.map_Ka = texture_map_loader.Load(directory, content); break; case "bump": case "map_Bump": mtl_info.map_Bump = texture_map_loader.Load(directory, content); break; case "map_d": mtl_info.map_d = texture_map_loader.Load(directory, content); break; case "Tf": mtl_info.Tf = ParseFloats(content, ' '); break; case "Ke": mtl_info.Ke = ParseFloats(content, ' '); break; default: throw new NotImplementedException(); } } return(mtl_file); }