Esempio n. 1
0
        public void AddEffect(string sourceFileName, string effectName, string materialName, bool fromExist)
        {
            string destOjbect = m_ProjectLocation + @"\Effects\" + Path.GetFileNameWithoutExtension(sourceFileName) + ".fxo";
            bool   success    = CompileEffect(sourceFileName, destOjbect);

            {
                if (Path.GetDirectoryName(sourceFileName) == m_ProjectLocation)
                {
                    sourceFileName = @"Effects\" + Path.GetFileName(sourceFileName);
                }
                string effectXml = string.Format(
                    @"<Effect name=""{0}"" object=""{1}"">{2}</Effect>", effectName, @"Effects\" + Path.GetFileName(destOjbect), sourceFileName);
                XmlDocument effectDoc = new XmlDocument();
                effectDoc.LoadXml(effectXml);
                XmlElement effectXmlNode = effectDoc.DocumentElement;

                XmlNode effectRoot = m_XmlDoc.DocumentElement.SelectSingleNode("Effects");
                if (effectRoot != null)
                {
                    effectRoot.AppendChild(m_XmlDoc.ImportNode(effectXmlNode, true));
                    TreeNode effectsTreeNode = treeViewAssets.Nodes["Effects"];
                    if (effectsTreeNode != null)
                    {
                        AddEffect(effectsTreeNode, effectRoot.LastChild);
                    }
                }
            }

            if (success && !string.IsNullOrEmpty(materialName))
            {
                uint size = RenderMethods.AddEffect(@"Effects\" + Path.GetFileName(destOjbect), effectName);
                if (size > 0)
                {
                    StringBuilder materialtString = new StringBuilder((int)size);
                    RenderMethods.GetMaterialXml(@"Effects\" + Path.GetFileName(destOjbect), materialtString, size);
                    File.WriteAllText(m_ProjectLocation + @"\Materials\" + materialName + ".mat", materialtString.ToString());

                    string materialtXml = string.Format(
                        @"<Material name=""{0}"">{1}</Material>", materialName, @"Materials\" + materialName + ".mat");
                    XmlDocument materialDoc = new XmlDocument();
                    materialDoc.LoadXml(materialtXml.ToString());
                    XmlElement materialXmlNode = materialDoc.DocumentElement;

                    XmlNode materialRoot = m_XmlDoc.DocumentElement.SelectSingleNode("Materials");
                    if (materialRoot != null)
                    {
                        materialRoot.AppendChild(m_XmlDoc.ImportNode(materialXmlNode, true));
                        TreeNode materialsTreeNode = treeViewAssets.Nodes["Materials"];
                        if (materialsTreeNode != null)
                        {
                            AddMaterial(materialsTreeNode, materialRoot.LastChild);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void AddEffect(string sourceFileName, string effectName, bool fromExist)
        {
            string destOjbect  = m_ProjectLocation + @"\Effects\" + Path.GetFileNameWithoutExtension(sourceFileName) + ".fxo";
            var    processInfo = new ProcessStartInfo
            {
                FileName = "fxc.exe",
#if (Debug)
                Arguments = "/Od /Zi /T fx_5_0 /nologo /Fo \"" + destOjbect + "\" \"" + sourceFileName + "\"",
#else
                Arguments = "/T fx_5_0 /nologo /Fo \"" + destOjbect + "\" \"" + sourceFileName + "\"",
#endif
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                WindowStyle            = ProcessWindowStyle.Hidden
            };
            var    fxcProcess  = Process.Start(processInfo);
            string compileInfo = fxcProcess.StandardOutput.ReadToEnd();
            string errorInfo   = fxcProcess.StandardError.ReadToEnd();

            fxcProcess.WaitForExit();

            m_OuputDeleagate?.Invoke(compileInfo, errorInfo);

            if (!string.IsNullOrEmpty(compileInfo))
            {
                uint size = RenderMethods.AddEffect(@"Effects\" + Path.GetFileName(destOjbect), sourceFileName, effectName);
                if (size > 0)
                {
                    StringBuilder effectXml = new StringBuilder((int)size);
                    RenderMethods.GetEffectXml(@"Effects\" + Path.GetFileName(destOjbect), effectXml, size);

                    XmlDocument effectDoc = new XmlDocument();
                    effectDoc.LoadXml(effectXml.ToString());
                    XmlElement effectXmlNode = effectDoc.DocumentElement;

                    XmlNode effectRoot = m_XmlDoc.DocumentElement.SelectSingleNode("Effects");
                    if (effectRoot != null)
                    {
                        effectRoot.AppendChild(m_XmlDoc.ImportNode(effectXmlNode, true));
                        TreeNode effectsTreeNode = treeViewAssets.Nodes["Effects"];
                        if (effectsTreeNode != null)
                        {
                            AddEffect(effectsTreeNode, effectRoot.LastChild);
                        }
                    }
                }
            }
        }