public CatMaterial Clone() { CatMaterial newMaterial = new CatMaterial(m_materialTemplate); // parameters if (m_parameters != null) { foreach (KeyValuePair <string, IEffectParameter> keyValue in m_parameters) { newMaterial.AddParameter(keyValue.Key, keyValue.Value); } } return(newMaterial); }
/** * @brief Create materialTemplate from .material file * * @param _filepath filepath * * @result the materialTemplate * */ public static CatMaterialTemplate LoadMaterialTemplate(string _filepath) { // create material template CatMaterialTemplate newMaterialTemplate = new CatMaterialTemplate(); CatMaterial materialPrototype = newMaterialTemplate.GetMaterialPrototype(); // load .material file XmlDocument doc = new XmlDocument(); doc.Load(_filepath); XmlNode nodeMaterial = doc.SelectSingleNode("Material"); XmlElement eleMaterial = (XmlElement)nodeMaterial; string materialName = eleMaterial.GetAttribute("fxname"); // read material parameter if (nodeMaterial != null) { foreach (XmlNode node in nodeMaterial.ChildNodes) { XmlElement eleNode = (XmlElement)node; string parameterName = eleNode.GetAttribute("name"); string parameterType = eleNode.GetAttribute("type"); string parameterValue = eleNode.GetAttribute("value"); IEffectParameter variable = CatMaterial.CreateVariable(parameterType, parameterValue); if (variable != null) { materialPrototype.AddParameter(parameterName, variable); } // check if should show in editor, by checking whether note="NotInEditor" string parameterNote = eleNode.GetAttribute("note"); if (parameterNote != null && parameterNote.Contains("NotInEditor")) { newMaterialTemplate.m_maskedParameters.Add(parameterName, true); } } } // load effect newMaterialTemplate.m_effect = Mgr <CatProject> .Singleton.contentManger.Load <Effect>("effect\\" + materialName); return(newMaterialTemplate); }