Esempio n. 1
0
 public static Material GetMaterial(string materialName)
 {
     return(Material.CreateMaterial(materialName));
 }
Esempio n. 2
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;
                    }
                }
            }
        }