private static Dictionary <string, Material> LoadMaterials(string directory, string[] tmp) { Dictionary <string, Material> materials; string matFileName = string.Join(" ", tmp.Skip(1)); string path = Path.Combine(directory, matFileName); materials = MaterialParser.LoadMaterials(path); return(materials); }
public static Dictionary <String, Material> LoadMaterials(string fileName) { MaterialParser parser = new MaterialParser(); Material tmpMaterial = null; try { foreach (string line in File.ReadLines(fileName)) { string[] readLineItems = line.Trim().Split(' '); switch (readLineItems[0]) { case "newmtl": tmpMaterial = new Material(); tmpMaterial.Name = string.Join(" ", readLineItems.Skip(1)); parser._materials.Add(tmpMaterial.Name, tmpMaterial); break; case "Ns": tmpMaterial.SpecularExponent = (float)Convert.ToDouble(readLineItems[1], _numbFormatInfo); break; case "d": tmpMaterial.Dissolve = (float)Convert.ToDouble(readLineItems[1], _numbFormatInfo); break; case "Tf": tmpMaterial.TransmissionFilter = GetVec3FromTabStr(readLineItems.Skip(1).ToArray(), _numbFormatInfo); break; case "illum": tmpMaterial.IllumModel = Convert.ToInt32(readLineItems[1]); break; case "Ka": tmpMaterial.Ambient = GetVec3FromTabStr(readLineItems.Skip(1).ToArray(), _numbFormatInfo); break; case "Kd": tmpMaterial.Diffuse = GetVec3FromTabStr(readLineItems.Skip(1).ToArray(), _numbFormatInfo); break; case "Ks": tmpMaterial.Specular = GetVec3FromTabStr(readLineItems.Skip(1).ToArray(), _numbFormatInfo); break; //case "map_Ka": // if (!material.HasTextures) // { // material.HasTextures = true; // } // material.AmbientMap = currentLine[1]; // break; //case "map_Kd": // if (!material.HasTextures) // { // material.HasTextures = true; // } // material.DiffuseMap = currentLine[1]; // break; //case "map_Ks": // if (!material.HasTextures) // { // material.HasTextures = true; // } // material.SpecularMap = currentLine[1]; // break; //case "map_Ns": // if (!material.HasTextures) // { // material.HasTextures = true; // } // material.SpecularExpMap = currentLine[1]; // break; //case "map_d": // if (!material.HasTextures) // { // material.HasTextures = true; // } // material.DissolveMap = currentLine[1]; // break; } } } catch (FileNotFoundException f) { throw new FileNotFoundException("MTL file not exist", f); } catch (ArgumentException ae) { throw new ArgumentException("MTL file is damaged", ae); } catch (Exception) { throw; } return(parser._materials); }