Ejemplo n.º 1
0
        public Material(string fileName)
        {
            Name = fileName;
            params_ = new ObservableCollection<MatParameter>();
            textures_ = new ObservableCollection<MatTexture>();
            techniques_ = new ObservableCollection<MatTechnique>();
            //setup other defaults

            string path = System.IO.Path.ChangeExtension(fileName, "xml");
            if (System.IO.File.Exists(path)) {
                XmlDocument doc = new XmlDocument();
                using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    doc.Load(fileStream);
                //doc.Load(path);

                foreach (XmlElement tech in doc.DocumentElement.GetElementsByTagName("technique"))
                    Techniques.Add(new MatTechnique(tech));
                foreach (XmlElement tex in doc.DocumentElement.GetElementsByTagName("texture")) {
                    string unit = tex.GetAttribute("unit");
                    MatTexture t = new MatTexture();
                    t.Name = tex.GetAttribute("name");
                    foreach (TexUnit u in Enum.GetValues(typeof(TexUnit))) {
                        if (u.ToString().ToLower().Equals(unit)) {
                            t.TextureUnit = u;
                            break;
                        }
                    }
                    Textures.Add(t);
                }
                foreach (XmlElement param in doc.DocumentElement.GetElementsByTagName("parameter"))
                    Params.Add(new MatParameter(param));
                foreach (XmlElement cull in doc.GetElementsByTagName("cull")) {
                    if (cull.HasAttribute("value")) {
                        if (cull.GetAttribute("value").Equals("cw"))
                            Culling = CullMode.CW;
                        else if (cull.GetAttribute("value").Equals("ccw"))
                            Culling = CullMode.CCW;
                        else
                            Culling = CullMode.NONE;
                    }
                }
                foreach (XmlElement cull in doc.GetElementsByTagName("shadowcull")) {
                    if (cull.HasAttribute("value")) {
                        if (cull.GetAttribute("value").Equals("cw"))
                            ShadowCull = CullMode.CW;
                        else if (cull.GetAttribute("value").Equals("ccw"))
                            ShadowCull = CullMode.CCW;
                        else
                            ShadowCull = CullMode.NONE;
                    }
                }
                foreach (XmlElement cull in doc.GetElementsByTagName("depthbias")) {
                    if (cull.HasAttribute("constant"))
                        DepthBiasConst = float.Parse(cull.GetAttribute("constant"));
                    if (cull.HasAttribute("slopescaled"))
                        DepthBiasSlope = float.Parse(cull.GetAttribute("slopescaled"));
                }
            }
        }
Ejemplo n.º 2
0
        public Material(string fileName)
        {
            Name        = fileName;
            params_     = new ObservableCollection <MatParameter>();
            textures_   = new ObservableCollection <MatTexture>();
            techniques_ = new ObservableCollection <MatTechnique>();
            //setup other defaults

            string path = System.IO.Path.ChangeExtension(fileName, "xml");

            if (System.IO.File.Exists(path))
            {
                XmlDocument doc = new XmlDocument();
                using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    doc.Load(fileStream);
                //doc.Load(path);

                foreach (XmlElement tech in doc.DocumentElement.GetElementsByTagName("technique"))
                {
                    Techniques.Add(new MatTechnique(tech));
                }
                foreach (XmlElement tex in doc.DocumentElement.GetElementsByTagName("texture"))
                {
                    string     unit = tex.GetAttribute("unit");
                    MatTexture t    = new MatTexture();
                    t.Name = tex.GetAttribute("name");
                    foreach (TexUnit u in Enum.GetValues(typeof(TexUnit)))
                    {
                        if (u.ToString().ToLower().Equals(unit))
                        {
                            t.TextureUnit = u;
                            break;
                        }
                    }
                    Textures.Add(t);
                }
                foreach (XmlElement param in doc.DocumentElement.GetElementsByTagName("parameter"))
                {
                    Params.Add(new MatParameter(param));
                }
                foreach (XmlElement cull in doc.GetElementsByTagName("cull"))
                {
                    if (cull.HasAttribute("value"))
                    {
                        if (cull.GetAttribute("value").Equals("cw"))
                        {
                            Culling = CullMode.CW;
                        }
                        else if (cull.GetAttribute("value").Equals("ccw"))
                        {
                            Culling = CullMode.CCW;
                        }
                        else
                        {
                            Culling = CullMode.NONE;
                        }
                    }
                }
                foreach (XmlElement cull in doc.GetElementsByTagName("shadowcull"))
                {
                    if (cull.HasAttribute("value"))
                    {
                        if (cull.GetAttribute("value").Equals("cw"))
                        {
                            ShadowCull = CullMode.CW;
                        }
                        else if (cull.GetAttribute("value").Equals("ccw"))
                        {
                            ShadowCull = CullMode.CCW;
                        }
                        else
                        {
                            ShadowCull = CullMode.NONE;
                        }
                    }
                }
                foreach (XmlElement cull in doc.GetElementsByTagName("depthbias"))
                {
                    if (cull.HasAttribute("constant"))
                    {
                        DepthBiasConst = float.Parse(cull.GetAttribute("constant"));
                    }
                    if (cull.HasAttribute("slopescaled"))
                    {
                        DepthBiasSlope = float.Parse(cull.GetAttribute("slopescaled"));
                    }
                }
            }
        }