private Texture2D AddTexture(string fileName) { string path = this.TextureDirectory + "/" + fileName; Texture2D texture = EditUtil.LoadTextureFromFile(path); if (texture != null) { texture.name = fileName; this.textureList.Add(texture); } return(texture); }
public static List <OBJMaterial> LoadMTL(string path) { if (!File.Exists(path)) { return(null); } string[] lines = File.ReadAllLines(path); List <OBJMaterial> materials = new List <OBJMaterial>(); OBJMaterial currentMaterial = null; foreach (string line in lines) { if (line.Length == 0) { continue; } if (line[0] == '#') { continue; } string[] tokens = line.Split(' '); if (tokens[0] == "newmtl") { currentMaterial = new OBJMaterial(); materials.Add(currentMaterial); currentMaterial.name = tokens[1]; } else if (tokens[0] == "map_Kd") { string dirName = Path.GetDirectoryName(path); string textureName = Path.GetFileNameWithoutExtension(tokens[1]); string textureExt = Path.GetExtension(tokens[1]); currentMaterial.albedo = EditUtil.LoadTextureFromFile(dirName + "/" + tokens[1]); currentMaterial.emission = EditUtil.LoadTextureFromFile(dirName + "/" + textureName + "_e" + textureExt); currentMaterial.normal = EditUtil.LoadTextureFromFile(dirName + "/" + textureName + "_n" + textureExt); currentMaterial.specular = EditUtil.LoadTextureFromFile(dirName + "/" + textureName + "_s" + textureExt); } } return(materials); }