Beispiel #1
0
        public MaterialFile GetTemplateItems()
        {
            if (m_templateItems == null)
            {
                m_templateItems = ReadMaterialXml(m_templateDir + "/template_items.xml");
                m_templateItems.AddParam("state", "anisotropy", "-1", null, null, null);
            }

            return(m_templateItems);
        }
Beispiel #2
0
        public Material()
        {
            m_objectName = null;

            m_resPaths = null;

            m_texturesList  = null;
            m_templatesList = null;
            m_templateItems = null;

            m_mySql = new ClientMySQL();
            m_mySql.Connect();

            m_translates = new Translate(m_templateDir + "/");

            if (saveMaterialThread == null)
            {
                saveMaterialThread = new Thread(new ThreadStart(ShowSaveMaterialWnd));
                saveMaterialThread.Start();
            }
        }
Beispiel #3
0
        public void SaveMaterial(String textureName, int lod, MaterialFile material)
        {
            ArrayList oldParams    = new ArrayList();
            String    materialName = GetMaterialNameFromTexture(textureName, lod);
            String    line;

            // чтение необновленного файла материала
            try
            {
                using (StreamReader materialList = new StreamReader((String)GetResoursesPaths()[lod] + "/" + materialName))
                {
                    while ((line = materialList.ReadLine()) != null)
                    {
                        oldParams.Add(line);
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }

            string[] contentArrOld = oldParams.ToArray(typeof(string)) as string[];
            // сохранить материал
            if (material != null)
            {
                ArrayList materialParams = material.GetParams();

                try
                {
                    ArrayList xmlLines = new ArrayList();
                    xmlLines.Add("<material>");

                    foreach (Hashtable param in materialParams)
                    {
                        String paramType = (String)param["paramType"];

                        if (paramType == "shader")
                        {
                            xmlLines.Add("\t<shader>" + (String)param["value"] + "</shader>");
                        }
                        else if (paramType == "state" || paramType == "param")
                        {
                            String paramString = "\t<" + paramType + " name=\"" + (String)param["paramName"] + "\" value=\"" + (String)param["value"] + "\" ";

                            if (param["valueType"] != null)
                            {
                                paramString += "type=\"" + (String)param["valueType"] + "\" ";
                            }

                            if (param["valueMin"] != null)
                            {
                                paramString += "vmin=\"" + (String)param["valueMin"] + "\" ";
                            }

                            if (param["valueMax"] != null)
                            {
                                paramString += "vmax=\"" + (String)param["valueMax"] + "\" ";
                            }

                            paramString += "/>";
                            xmlLines.Add(paramString);
                        }
                        else if (paramType == "texture" || paramType == "texture3d" || paramType == "cubemap")
                        {
                            String paramString = "\t<" + paramType + " src=\"" + (String)param["paramName"] + "\" ";

                            if (param["valueType"] != null)
                            {
                                paramString += "alphablend=\"" + (String)param["valueType"] + "\" ";
                            }

                            if (param["value"] != null)
                            {
                                paramString += "level=\"" + (String)param["value"] + "\" ";
                            }

                            paramString += "/>";
                            xmlLines.Add(paramString);
                        }
                        else if (paramType == "animation")
                        {
                            xmlLines.Add("\t<animation level=\"" + (String)param["paramName"] + "\" delta=\"" + (String)param["value"] + "\">" +
                                         (String)param["valueType"] + "</animation>");
                        }
                    }

                    xmlLines.Add("</material>");

                    string   res        = (String)(GetResoursesPaths()[lod]) + "/" + materialName;
                    string[] contentArr = (String[])xmlLines.ToArray(typeof(String));

                    //если изменени¤ в материале произошли, перезаписываем файл
                    bool isMaterialChanged = false;

                    if (contentArr.Length != contentArrOld.Length)
                    {
                        isMaterialChanged = true;
                    }

                    if (!isMaterialChanged)
                    {
                        for (int j = 0; j < contentArr.Length; j++)
                        {
                            if (contentArr[j] != contentArrOld[j])
                            {
                                isMaterialChanged = true;
                                break;
                            }
                        }
                    }

                    if ((isMaterialChanged) && (contentArrOld.Length != 0))
                    {
                        isSaveMaterial = true;
                        if (MessageBox.Show("¬ы действительно хотите сохранить материал: \n “екстура: " + textureName + "\n ќбъект: " + GetModelName(lod) + "\n Ћод: " + lod.ToString() + "?", "ѕодтверждение сохранени¤ материала", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            WriteFile(res, contentArr, xmlLines);
                        }
                    }
                    else if (contentArrOld.Length == 0)
                    {
                        WriteFile(res, contentArr, xmlLines);
                    }
                    isSaveMaterial = false;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Beispiel #4
0
        private MaterialFile ReadMaterialXml(String xmlPath)
        {
            MaterialFile newMaterial = null;

            try
            {
                using (XmlReader xmlReader = XmlReader.Create(xmlPath))
                {
                    xmlReader.MoveToContent();
                    newMaterial = new MaterialFile();
                    bool isAnisotropy    = false;
                    int  anisotropyValue = 0;

                    while (xmlReader.Read())
                    {
                        if (xmlReader.Name == "shader")
                        {
                            newMaterial.AddParam(xmlReader.Name,
                                                 null,
                                                 xmlReader.ReadString(),
                                                 null,
                                                 null,
                                                 null);
                        }
                        else if (xmlReader.Name == "state" || xmlReader.Name == "param")
                        {
                            if (xmlReader.GetAttribute("name") == "anisotropy")
                            {
                                isAnisotropy    = true;
                                anisotropyValue = int.Parse(xmlReader.GetAttribute("value"));
                            }
                            else
                            {
                                if ((xmlReader.GetAttribute("name") == "min_filter") || (xmlReader.GetAttribute("name") == "mipmap") ||
                                    (xmlReader.GetAttribute("name") == "mag_filter") || (xmlReader.GetAttribute("name") == "mipmap_bias") ||
                                    (xmlReader.GetAttribute("name") == "anisotropy_power"))
                                {
                                    isAnisotropy = false;
                                }

                                newMaterial.AddParam(xmlReader.Name,
                                                     xmlReader.GetAttribute("name"),
                                                     xmlReader.GetAttribute("value"),
                                                     xmlReader.GetAttribute("type"),
                                                     xmlReader.GetAttribute("vmin"),
                                                     xmlReader.GetAttribute("vmax"));
                            }
                        }
                        else if (xmlReader.Name == "texture" || xmlReader.Name == "texture3d" || xmlReader.Name == "cubemap")
                        {
                            newMaterial.AddParam(xmlReader.Name,
                                                 xmlReader.GetAttribute("src"),        // в качестве имени параметра
                                                 xmlReader.GetAttribute("level"),      // в качестве значени¤
                                                 xmlReader.GetAttribute("alphablend"), // в качестве типа значени¤
                                                 null,
                                                 null);
                        }
                        else if (xmlReader.Name == "animation")
                        {
                            newMaterial.AddParam(xmlReader.Name,
                                                 xmlReader.GetAttribute("level"), // в качестве имени параметра
                                                 xmlReader.GetAttribute("delta"), // в качестве значени¤
                                                 xmlReader.ReadInnerXml(),        // в качестве типа значени¤
                                                 null,
                                                 null);
                        }
                    }

                    if (isAnisotropy)
                    {
                        if (anisotropyValue > 0)
                        {
                            newMaterial.AddParam("state", "min_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap", "2", null, null, null);
                            newMaterial.AddParam("state", "mag_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap_bias", "0.0", "float", "0.0", "3.0");
                            newMaterial.AddParam("state", "anisotropy_power", xmlReader.GetAttribute("value"), null, null, null);
                        }
                        else if (anisotropyValue == 0)
                        {
                            newMaterial.AddParam("state", "min_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap", "2", null, null, null);
                            newMaterial.AddParam("state", "mag_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap_bias", "0.0", "float", "0.0", "3.0");
                            newMaterial.AddParam("state", "anisotropy_power", "1", null, null, null);
                        }
                        else if (anisotropyValue == -3)
                        {
                            newMaterial.AddParam("state", "min_filter", "nearest", null, null, null);
                            newMaterial.AddParam("state", "mipmap", "1", null, null, null);
                            newMaterial.AddParam("state", "mag_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap_bias", "0.0", "float", "0.0", "3.0");
                            newMaterial.AddParam("state", "anisotropy_power", "1", null, null, null);
                        }
                        else if (anisotropyValue == -2)
                        {
                            newMaterial.AddParam("state", "min_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap", "0", null, null, null);
                            newMaterial.AddParam("state", "mag_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap_bias", "0.0", "float", "0.0", "3.0");
                            newMaterial.AddParam("state", "anisotropy_power", "1", null, null, null);
                        }
                        else if (anisotropyValue == -1)
                        {
                            newMaterial.AddParam("state", "min_filter", "nearest", null, null, null);
                            newMaterial.AddParam("state", "mipmap", "0", null, null, null);
                            newMaterial.AddParam("state", "mag_filter", "nearest", null, null, null);
                            newMaterial.AddParam("state", "mipmap_bias", "0.0", "float", "0.0", "3.0");
                            newMaterial.AddParam("state", "anisotropy_power", "1", null, null, null);
                        }
                        else
                        {
                            newMaterial.AddParam("state", "min_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap", "2", null, null, null);
                            newMaterial.AddParam("state", "mag_filter", "linear", null, null, null);
                            newMaterial.AddParam("state", "mipmap_bias", "0.0", "float", "0.0", "3.0");
                            newMaterial.AddParam("state", "anisotropy_power", "1", null, null, null);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(newMaterial);
        }