コード例 #1
0
 private static void ParseMaterialLibrary(string filename)
 {
     string[] lines = System.IO.File.ReadAllLines(filename);
     Material current = null;
     string materialName;
     foreach (string line in lines)
     {
         if (line.StartsWith("newmtl"))
         {
             current = new Material();
             materialName = line.Split(new char[] { ' ' })[1];
             _materialLibrary[_currentMaterialLibrary].Add(materialName, current);
         }
         else if (line.StartsWith("Ka"))
         {
             string[] parts = line.Split(new char[] { ' ' });
             current.Ambient.X = float.Parse(parts[1]);
             current.Ambient.Y = float.Parse(parts[2]);
             current.Ambient.Z = float.Parse(parts[3]);
         }
         else if (line.StartsWith("Kd"))
         {
             string[] parts = line.Split(new char[] { ' ' });
             current.Diffuse.X = float.Parse(parts[1]);
             current.Diffuse.Y = float.Parse(parts[2]);
             current.Diffuse.Z = float.Parse(parts[3]);
         }
         else if (line.StartsWith("Ks"))
         {
             string[] parts = line.Split(new char[] { ' ' });
             current.Specular.X = float.Parse(parts[1]);
             current.Specular.Y = float.Parse(parts[2]);
             current.Specular.Z = float.Parse(parts[3]);
         }
         else if (line.StartsWith("Ns"))
         {
             current.Shininess = (float.Parse(line.Split(new char[] { ' ' })[1]) / 1000f) * 128.0f;
         }
         else if (line.StartsWith("map_Kd"))
         {
             current.DiffuseTexture = Assets.GetTexture(line.Split(new char[] { ' ' })[1]);
         }
     }
 }
コード例 #2
0
ファイル: ModelMesh.cs プロジェクト: jikoriko/OpentkEngine
 public void SetMaterial(Material material)
 {
     _material = material;
 }