Ejemplo n.º 1
0
 /// <summary>
 /// luo uusi materiaali.
 /// jos materiaaliName niminen materiaali on luotu jo, palauta se.
 /// </summary>
 /// <param name="materialName"></param>
 /// <returns></returns>
 static Material CreateMaterial(string materialName)
 {
     if (materials.ContainsKey(materialName))
     {
         return materials[materialName];
     }
     Material mat = new Material();
     mat.materialName = materialName;
     materials.Add(materialName, mat);
     return mat;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// lataa materiaalitiedot .material tiedostosta (ogre materiaali)
 /// </summary>
 public static Material Load(string fileName)
 {
     Material mat = new Material(fileName);
     return mat;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// aseta materiaali ellei jo käytössä
 /// </summary>
 public void SetMaterial()
 {
     if (currentMaterialName == materialName) return;
     currentMaterialName = materialName;
     for (int q = 0; q < MaxTextures; q++)
         if (Textures[q].Tex != null)
             Textures[q].Tex.Bind(q);
     
     CurrentMaterial = this;
 }
Ejemplo n.º 4
0
        void LoadMaterial(string fileName)
        {
            using (System.IO.StreamReader file = new System.IO.StreamReader(Settings.ModelDir + fileName))
            {
                // tiedosto muistiin
                string data = file.ReadToEnd();

                // pilko se
                string[] lines = data.Split('\n');

                Material mat = new Material();
                int curTexture = -1;

                for (int q = 0; q < lines.Length; q++)
                {
                    string line = lines[q];
                    line = line.Trim('\r', '\t', ' ');
                    if (line.StartsWith("//")) continue;
                    string[] ln = line.Split(' '); // pilko datat

                    if (ln[0] == "material")
                    {
                        curTexture = -1;
                        mat = Material.CreateMaterial(ln[1]);
                        Log.WriteLine("Material: " + mat.materialName, false);
                        continue;
                    }

                    if (ln[0] == "shader")
                    {
                        mat.ShaderName = ln[1]; // ota shaderin nimi
                        continue;
                    }

                    // lataa texture
                    if (ln[0] == "texture")
                    {
                        curTexture++;
                        if (ln[1] == "none") continue;
                        mat.Textures[curTexture].Tex = Texture.Load(ln[1]);
                        continue;
                    }

                    if (ln[0] == "tex_coord_set")
                    {
                        mat.Textures[curTexture].TexCoordSet = uint.Parse(ln[1]);
                        continue;
                    }

                    if (ln[0] == "env_map")
                    {
                        if (ln[1] == "spherical")
                            mat.Textures[curTexture].EnvMap = TextureInfo.EnvMaps.Spherical;
                        else if (ln[1] == "cubic_reflection")
                            mat.Textures[curTexture].EnvMap = TextureInfo.EnvMaps.CubicReflection;
                        else
                            mat.Textures[curTexture].EnvMap = TextureInfo.EnvMaps.None;
                        continue;
                    }

                    // Ambient color
                    if (ln[0] == "ambient")
                    {
                        mat.AmbientColor = new Vector4(MathExt.GetFloat(ln[1]), MathExt.GetFloat(ln[2]), MathExt.GetFloat(ln[3]), 1);
                        continue;
                    }
                    // Diffuse color
                    if (ln[0] == "diffuse")
                    {
                        mat.DiffuseColor = new Vector4(MathExt.GetFloat(ln[1]), MathExt.GetFloat(ln[2]), MathExt.GetFloat(ln[3]), 1);
                        continue;
                    }
                    // Specular color
                    if (ln[0] == "specular")
                    {
                        mat.SpecularColor = new Vector4(MathExt.GetFloat(ln[1]), MathExt.GetFloat(ln[2]), MathExt.GetFloat(ln[3]), MathExt.GetFloat(ln[4]));
                        continue;
                    }
                }
            }
        }