Beispiel #1
0
        public void Save(String asFile, frmMain apMainForm)
        {
            XmlDocument Doc = new XmlDocument();

            XmlElement DocRoot = Doc.CreateElement("Material");

            Doc.AppendChild(DocRoot);


            XmlElement MainElem = Doc.CreateElement("Main");

            DocRoot.AppendChild(MainElem);

            MainElem.SetAttribute("Type", (String)apMainForm.objMaterialTypes.SelectedItem);
            MainElem.SetAttribute("PhysicsMaterial", msPhysicsMaterial);
            MainElem.SetAttribute("UseAlpha", mbUseAlpha?"True" : "False");
            MainElem.SetAttribute("DepthTest", mbDepthTest?"True" : "False");
            MainElem.SetAttribute("Value", msValue);

            XmlElement TexElem = Doc.CreateElement("TextureUnits");

            DocRoot.AppendChild(TexElem);

            //Textures
            for (int i = 0; i < apMainForm.objTextureUnitTypes.Items.Count; i++)
            {
                HplTextureUnit TexUnit = (HplTextureUnit)mvTextureUnits[i];

                String     sTexType  = (String)apMainForm.objTextureUnitTypes.Items[i];
                XmlElement ChildElem = Doc.CreateElement(sTexType);

                /*if(TexUnit.msFile == ""){
                 *      MessageBox.Show("Could not save! Material has no "+(String)apMainForm.objTextureUnitTypes.Items[i]+" texture file!","Error");
                 *      return;
                 * }*/

                ChildElem.SetAttribute("File", TexUnit.msFile);
                ChildElem.SetAttribute("Compress", "false");
                ChildElem.SetAttribute("Type", "2D");
                ChildElem.SetAttribute("Mipmaps", TexUnit.mbMipMaps? "true" : "false");
                ChildElem.SetAttribute("Wrap", (String)apMainForm.objWrapModes.Items[(int)TexUnit.mWrapMode]);
                ChildElem.SetAttribute("AnimMode", TexUnit.msAnimMode);
                ChildElem.SetAttribute("AnimFrameTime", TexUnit.msFrameTime);
                ChildElem.SetAttribute("Type", TexUnit.msType);

                TexElem.AppendChild(ChildElem);
            }

            Doc.Save(asFile);
        }
Beispiel #2
0
        public void Load(String asFile)
        {
            XmlDocument Doc = new XmlDocument();

            Doc.Load(asFile);

            XmlElement DocRoot = (XmlElement)Doc.FirstChild;

            //Iterate trough all directories.
            for (int child_count = 0; child_count < DocRoot.ChildNodes.Count; child_count++)
            {
                XmlElement ChildNode = (XmlElement)DocRoot.ChildNodes[child_count];

                if (ChildNode.Name == "Main")
                {
                    String sType = ChildNode.GetAttribute("Type");
                    for (int i = 0; i < mvTypeNames.Length; i++)
                    {
                        if (sType == mvTypeNames[i])
                        {
                            mType = (eHplMaterialType)i;
                            break;
                        }
                    }

                    msPhysicsMaterial = ChildNode.GetAttribute("PhysicsMaterial");

                    mbUseAlpha  = ChildNode.GetAttribute("UseAlpha") == "True"? true : false;
                    mbDepthTest = ChildNode.GetAttribute("DepthTest") == "False"? false : true;

                    try{
                        msValue = ChildNode.GetAttribute("Value");
                    }
                    catch {
                        msValue = "1";
                    }
                }
                else if (ChildNode.Name == "TextureUnits")
                {
                    for (int tex = 0; tex < ChildNode.ChildNodes.Count; tex++)
                    {
                        XmlElement     TexNode = (XmlElement)ChildNode.ChildNodes[tex];
                        HplTextureUnit TexUnit = (HplTextureUnit)mvTextureUnits[tex];

                        //MessageBox.Show("MIp: "+TexNode.GetAttribute("MipMaps"),"Test");

                        TexUnit.msFile      = TexNode.GetAttribute("File");
                        TexUnit.mbMipMaps   = TexNode.GetAttribute("Mipmaps").ToLower() == "true";
                        TexUnit.msAnimMode  = TexNode.GetAttribute("AnimMode");
                        TexUnit.msFrameTime = TexNode.GetAttribute("AnimFrameTime");
                        try{
                            TexUnit.msType = TexNode.GetAttribute("Type");
                        }
                        catch {
                            TexUnit.msType = "2D";
                        }


                        String sWrapMode = TexNode.GetAttribute("Wrap").ToLower();
                        if (sWrapMode == "repeat")
                        {
                            TexUnit.mWrapMode = eHplWrapType.Repeat;
                        }
                        else if (sWrapMode == "clamp")
                        {
                            TexUnit.mWrapMode = eHplWrapType.Clamp;
                        }
                        else if (sWrapMode == "clamptoedge")
                        {
                            TexUnit.mWrapMode = eHplWrapType.ClampToEdge;
                        }
                    }
                }
            }
        }