Exemple #1
0
        public void ModifyEffect(XmlNode effectNode)
        {
            string sourceFileName = effectNode.InnerText;

            if (!File.Exists(sourceFileName) && File.Exists(m_ProjectLocation + @"\" + sourceFileName))
            {
                sourceFileName = m_ProjectLocation + @"\" + sourceFileName;
            }

            string effectName = effectNode.Attributes["name"].Value;

            string destOjbect = m_ProjectLocation + @"\Effects\" + Path.GetFileNameWithoutExtension(sourceFileName) + ".fxo";

            if (!CompileEffect(sourceFileName, destOjbect))
            {
                return;
            }

            uint size = RenderMethods.ModifyEffect(@"Effects\" + Path.GetFileName(destOjbect), effectName);

            if (size > 0)
            {
                StringBuilder materialtString = new StringBuilder((int)size);
                RenderMethods.GetMaterialXml(@"Effects\" + Path.GetFileName(destOjbect), materialtString, size);

                XmlDocument materialDoc = new XmlDocument();
                materialDoc.LoadXml(materialtString.ToString());
                XmlElement newMaterialNode = materialDoc.DocumentElement;

                ReSetMaterial(newMaterialNode, effectName);
            }
        }
Exemple #2
0
        public void PickActor(Point cursor)
        {
            int  mesh    = -1;
            uint actorId = RenderMethods.GetPickedActor(cursor.X, cursor.Y, ref mesh);

            m_ProjectView.SelectActorNode(actorId);
        }
Exemple #3
0
        public void AddMaterial(string materialName, string materialFile, XmlNode materialNode)
        {
            string bmpPath = m_BmpTempDir + Path.GetFileNameWithoutExtension(materialFile) + ".bmp";

            RenderMethods.AddMaterial(@"Materials\" + Path.GetFileName(materialFile), bmpPath);

            ListViewItem item = new ListViewItem();

            item.Text = materialName;
            item.Name = materialFile;
            item.Tag  = materialNode;
            listViewMaterials.Items.Add(item);

            try
            {
                Image original = Image.FromFile(bmpPath);
                if (original != null)
                {
                    imageListLarge.Images.Add(original);
                    item.ImageIndex = imageListLarge.Images.Count - 1;
                }
            }
            catch (OutOfMemoryException)
            {
            }
        }
Exemple #4
0
        private void RenderView_Resize(object sender, EventArgs e)
        {
            Control control = (Control)sender;

            if (control.Width != 0 && control.Height != 0)
            {
                RenderMethods.ResizeWnd(control.Width, control.Height);
            }
        }
Exemple #5
0
        public bool PreFilterMessage(ref Message m)
        {
            if (m_renderPanel != null && m_renderPanel.IsHandleCreated)
            {
                if (m.Msg == WM_LBUTTONDOWN || m.Msg == WM_RBUTTONDOWN || m.Msg == WM_MBUTTONDOWN)
                {
                    CheckFakeFocus();
                }

                if (m.Msg == WM_MOUSEWHEEL && m_fakeFocus)
                {
                    RenderMethods.WndProc(m_renderPanel.Handle, m.Msg, m.WParam, m.LParam);
                    return(true);
                }
                if (m.HWnd == m_renderPanel.Handle || (m_fakeFocus && (m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP)))
                {
                    switch (m.Msg)
                    {
                    case WM_LBUTTONDOWN:
                    case WM_RBUTTONDOWN:
                    case WM_MBUTTONDOWN:
                    case WM_KEYDOWN:
                    case WM_KEYUP:
                    case WM_SYSKEYDOWN:
                    case WM_SYSKEYUP:
                    case WM_LBUTTONUP:
                    case WM_LBUTTONDBLCLK:
                    case WM_RBUTTONUP:
                    case WM_RBUTTONDBLCLK:
                    case WM_MBUTTONUP:
                    case WM_MBUTTONDBLCLK:
                    case WM_MOUSEMOVE:
                    case WM_MOUSEWHEEL:
                    case WM_CHAR:
                    case WM_CLOSE:
                    {
                        if (m_fakeFocus && m.Msg == WM_LBUTTONDOWN)
                        {
                            System.Drawing.Point position = Cursor.Position;
                            double distance = Math.Round(Math.Sqrt(
                                                             Math.Pow((position.X - m_mouseDownPosition.X), 2) +
                                                             Math.Pow((position.Y - m_mouseDownPosition.Y), 2)), 1);
                            if (distance < 3)
                            {
                                System.Drawing.Point relativeToForm = m_renderPanel.PointToClient(position);
                                m_formMain.PickActor(relativeToForm);
                            }
                        }
                        RenderMethods.WndProc(m_renderPanel.Handle, m.Msg, m.WParam, m.LParam);

                        return(true);
                    }
                    }
                }
            }
            return(false);
        }
Exemple #6
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);
                        }
                    }
                }
            }
        }
Exemple #7
0
 private void FXStudioForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     try
     {
         RenderMethods.DestroyInstance();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemple #8
0
        private void ReSetMaterial(XmlElement newMaterialNode, string effectName)
        {
            TreeNode materialRoot = treeViewAssets.Nodes["Materials"];

            if (materialRoot == null)
            {
                return;
            }

            foreach (TreeNode child in materialRoot.Nodes)
            {
                if (child.FirstNode.Text != effectName)
                {
                    continue;
                }

                XmlNode oldMaterialNode = child.Tag as XmlNode;
                if (oldMaterialNode == null)
                {
                    continue;
                }

                XmlNode variables = newMaterialNode.SelectSingleNode("Variables");
                foreach (XmlNode childVar in variables)
                {
                    string  varName = childVar.Name;
                    XmlNode varNode = oldMaterialNode.SelectSingleNode(varName);
                    if (varNode != null)
                    {
                        childVar.InnerText = varNode.InnerText;
                        if (childVar.Attributes["resourcename"] != null && varNode.Attributes["resourcename"] != null)
                        {
                            childVar.Attributes["resourcename"].Value = varNode.Attributes["resourcename"].Value;
                        }
                    }
                }

                XmlDocument materialDoc = new XmlDocument();
                materialDoc.LoadXml(newMaterialNode.OuterXml);
                XmlWriter writer = XmlWriter.Create(child.Name, new XmlWriterSettings()
                {
                    Indent             = true,
                    IndentChars        = "\t",
                    OmitXmlDeclaration = true
                });
                materialDoc.Save(writer);
                writer.Flush();
                writer.Close();

                child.Tag = newMaterialNode;
                RenderMethods.ModifyMaterial(@"Materials\" + Path.GetFileName(child.Name), true);
            }
        }
Exemple #9
0
        public void ModifyMaterial(string name, string value)
        {
            if (m_MaterialsHandle.Visible)
            {
                int      select        = m_MaterialsHandle.GetSelectedIndex();
                TreeNode materialsRoot = treeViewAssets.Nodes["Materials"];
                treeViewAssets.SelectedNode = materialsRoot.Nodes[select];
            }

            XmlNode materialNode = treeViewAssets.SelectedNode.Tag as XmlNode;

            if (materialNode != null)
            {
                XmlNode varRoot = materialNode.SelectSingleNode("Variables");
                if (varRoot == null)
                {
                    return;
                }

                XmlNode variable = varRoot.SelectSingleNode(name);
                if (variable == null)
                {
                    return;
                }

                if (variable.Attributes["resourcename"] != null)
                {
                    variable.Attributes["resourcename"].Value = value;
                }
                else
                {
                    variable.InnerText = value;
                }

                XmlDocument materialDoc = new XmlDocument();
                materialDoc.LoadXml(materialNode.OuterXml);
                XmlWriter writer = XmlWriter.Create(treeViewAssets.SelectedNode.Name, new XmlWriterSettings()
                {
                    Indent             = true,
                    IndentChars        = "\t",
                    OmitXmlDeclaration = true
                });
                materialDoc.Save(writer);
                writer.Flush();
                writer.Close();

                treeViewAssets.SelectedNode.Tag = materialNode;
                m_MaterialsHandle.ModifyMaterial();
                RenderMethods.ModifyMaterial(@"Materials\" + Path.GetFileName(treeViewAssets.SelectedNode.Name), false);
            }
        }
Exemple #10
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);
                        }
                    }
                }
            }
        }
Exemple #11
0
        private void toolStripButtonPlane_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc          = new XmlDocument();
            XmlElement  geometryElement = xmlDoc.CreateElement("Plane");

            geometryElement.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "type", "Plane"));
            geometryElement.AppendChild(XmlUtility.CreateTransformComponent(xmlDoc, "0", "0"));
            geometryElement.AppendChild(XmlUtility.CreatePlaneRenderComponent(xmlDoc));

            if (RenderMethods.AddActor(geometryElement.OuterXml) > 0)
            {
                m_ProjectView.AddActorNode(geometryElement);
            }
        }
Exemple #12
0
        private void panelRender_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode effectNode = (TreeNode)e.Data.GetData(typeof(TreeNode).ToString(), false);

            if (effectNode != null)
            {
                XmlNode element = (XmlNode)effectNode.Tag;
                if (element != null)
                {
                    Point targetPoint = panelRender.PointToClient(new Point(e.X, e.Y));
                    uint  actorId     = RenderMethods.GetPickedActor(targetPoint.X, targetPoint.Y);
                    m_ChangeDelegate?.Invoke(element, actorId);
                }
            }
        }
Exemple #13
0
 private void panelRender_DragOver(object sender, DragEventArgs e)
 {
     string[] formats = e.Data.GetFormats();
     if (formats.Contains(typeof(TreeNode).ToString()))
     {
         Point targetPoint = panelRender.PointToClient(new Point(e.X, e.Y));
         uint  actorId     = RenderMethods.GetPickedActor(targetPoint.X, targetPoint.Y);
         if (actorId != 0)
         {
             e.Effect = DragDropEffects.Copy;
         }
         else
         {
             e.Effect = DragDropEffects.None;
         }
     }
 }
        private void backgroundWorkerLoading_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            RenderMethods.ImportModel(m_SourceFileName, m_DestFileName, (percent, error) =>
            {
                try
                {
                    worker.ReportProgress((int)(percent * 100), error);
                    e.Result = error;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                return(!worker.CancellationPending);
            });
        }
Exemple #15
0
        private void toolStripButtonTransform_Click(object sender, EventArgs e)
        {
            ToolStripButton select = sender as ToolStripButton;
            int             i      = 0;

            foreach (ToolStripButton button in m_TransformButtons)
            {
                if (button == select)
                {
                    button.Checked = true;
                    RenderMethods.SetTransformType(i);
                }
                else
                {
                    button.Checked = false;
                }

                i++;
            }
        }
Exemple #16
0
        private void toolStripButtonImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "All supported formats (*.fbx; *.dae; *.blend; *.3ds; *.ase; *.obj; *.ply; *.x; *.ms3d;)|" +
                            "*.fbx; *.dae; *.blend; *.3ds; *.ase; *.obj; *.ply; *.x; *.ms3d;|" +
                            "Autodesk FBX (*.fbx)|*.fbx|" + "Autodesk 3DS (*.3ds)|*.3ds|" + "Autodesk ASE (*.ase)|*.ase|" +
                            "Collada Model (*.dae)|*.dae|" + "Blender 3D (*.blend)|*.blend|" + "Stanford Polygon Library (*.ply)|*.ply|" +
                            "Wavefront Object (*.obj)|*.obj|" + "Milkshape 3D (*.ms3d)|*.ms3d";
            dialog.FilterIndex      = 1;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string destFileName = m_ProjectLocation + @"\Models\" + Path.GetFileNameWithoutExtension(dialog.FileName) + ".model";
                if (!Directory.Exists(Path.GetDirectoryName(destFileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destFileName));
                }

                LoadingProgressDialog loadDlg = new LoadingProgressDialog();
                loadDlg.SourceFileName = dialog.FileName;
                loadDlg.DestFileName   = destFileName;
                if (loadDlg.ShowDialog() == DialogResult.OK)
                {
                    string fileName = Path.GetFileNameWithoutExtension(destFileName);
                    fileName = fileName.First().ToString().ToUpper() + fileName.Substring(1);
                    XmlDocument xmlDoc       = new XmlDocument();
                    XmlElement  modelElement = xmlDoc.CreateElement(fileName);

                    modelElement.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "type", "Model"));
                    modelElement.AppendChild(XmlUtility.CreateTransformComponent(xmlDoc));
                    modelElement.AppendChild(XmlUtility.CreateModelRenderComponent(xmlDoc, destFileName));

                    if (RenderMethods.AddActor(modelElement.OuterXml) > 0)
                    {
                        m_ProjectView.AddActorNode(modelElement);
                    }
                }
            }
        }
Exemple #17
0
        private void FXStudioForm_Load(object sender, EventArgs e)
        {
            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "FXStudio.Layout.config");

            if (File.Exists(configFile))
            {
                panelAllView.LoadFromXml(configFile, m_dockContent);
            }
            else
            {
                ResetLayout();
            }

            panelAllView.DockLeftPortion  = panelAllView.Width * 0.20d;
            panelAllView.DockRightPortion = panelAllView.DockLeftPortion;

            IntPtr hInstance   = Marshal.GetHINSTANCE(this.GetType().Module);
            var    panelRender = m_RenderView.GetRenderPanel();

            m_messageHandler.ResetRenderPanel(panelRender);

            try
            {
                if (!RenderMethods.CreateInstance(hInstance, IntPtr.Zero, panelRender.Handle, 1, panelRender.Width, panelRender.Height))
                {
                    this.Close();
                }

                if (panelRender.Width != 0 && panelRender.Height != 0)
                {
                    RenderMethods.ResizeWnd(panelRender.Width, panelRender.Height);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.Close();
            }
        }
Exemple #18
0
        private void panelRender_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode materialNode = (TreeNode)e.Data.GetData(typeof(TreeNode).ToString(), false);

            if (materialNode != null)
            {
                Point targetPoint = panelRender.PointToClient(new Point(e.X, e.Y));
                int   mesh        = -1;
                uint  actorId     = RenderMethods.GetPickedActor(targetPoint.X, targetPoint.Y, ref mesh);
                m_ChangeDelegate?.Invoke(materialNode.Name, actorId, mesh);
                return;
            }

            ListViewItem item = (ListViewItem)e.Data.GetData(typeof(ListViewItem).ToString(), false);

            if (item != null)
            {
                Point targetPoint = panelRender.PointToClient(new Point(e.X, e.Y));
                int   mesh        = -1;
                uint  actorId     = RenderMethods.GetPickedActor(targetPoint.X, targetPoint.Y, ref mesh);
                m_ChangeDelegate?.Invoke(item.Name, actorId, mesh);
            }
        }
Exemple #19
0
        public void Application_Idle(object sender, EventArgs e)
        {
            if (m_formMain.ProjectLoaded && m_formMain.WindowState != FormWindowState.Minimized)
            {
                try
                {
                    // Render the scene if we are idle
                    if (m_renderPanel.Handle != null && m_renderPanel.Visible)
                    {
                        RenderMethods.RenderFrame();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                if (m_fakeFocus)
                {
                    m_formMain.Invalidate();
                }
            }
        }
Exemple #20
0
 private void toolStripMenuItemFp_Click(object sender, EventArgs e)
 {
     toolStripMenuItemOrbit.Checked = false;
     toolStripMenuItemFp.Checked    = true;
     RenderMethods.SetCameraType(1);
 }
Exemple #21
0
        private void OpenProject(string project)
        {
            RenderMethods.OpenProject(project);
            m_ProjectLocation = Path.GetDirectoryName(project);

            m_ProjectView.UpdateProject(project, selectedNode =>
            {
                if (m_PropertiesView.UpdateProjectProperties(selectedNode))
                {
                    int selectAcotrId = m_ProjectView.GetSelectActorId();
                    if (selectAcotrId > 2)
                    {
                        RenderMethods.SetPickedActor((uint)selectAcotrId);
                    }
                    else
                    {
                        RenderMethods.SetPickedActor(0);
                    }
                }
                else
                {
                    RenderMethods.SetPickedActor(0);
                }
            });

            string assetFile = m_ProjectLocation + @"\" + Path.GetFileNameWithoutExtension(project) + ".asset";

            m_AssetsView.UpdateAssets(assetFile, m_PropertiesView.UpdateAssetProperties, m_outputView.UpdateCompileInfo);

            m_PropertiesView.SetMoveActorDelegate((string component, string attribute, Inspector.Vector3 value) =>
            {
                int actorId = m_ProjectView.GetSelectActorId();

                XmlDocument xmlDoc  = new XmlDocument();
                XmlElement xmlActor = xmlDoc.CreateElement("Actor");

                xmlActor.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "id", (actorId > 2 ? actorId : 0).ToString()));

                XmlElement transformComponent = xmlDoc.CreateElement(component);;
                XmlElement transformType      = xmlDoc.CreateElement(attribute);
                transformComponent.AppendChild(transformType);
                transformType.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "x", value.X.ToString()));
                transformType.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "y", value.Y.ToString()));
                transformType.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "z", value.Z.ToString()));
                xmlActor.AppendChild(transformComponent);

                RenderMethods.ModifyActor(xmlActor.OuterXml);
            });

            m_RenderView.SetChangeEffectDelegate((effectNode, actorId) =>
            {
                m_ProjectView.SelectActorNode(actorId);
                XmlNode actorNode = m_ProjectView.GetSelectActorXml();

                XmlDocument xmlDoc  = new XmlDocument();
                XmlElement xmlActor = xmlDoc.CreateElement("Actor");

                xmlActor.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "id", actorId.ToString()));

                XmlElement renderComponent = null;
                string nodeType            = actorNode.Attributes["type"].Value;
                if (nodeType == "Model")
                {
                    renderComponent = xmlDoc.CreateElement("ModelRenderComponent");
                }
                else if (nodeType == "Cube")
                {
                    renderComponent = xmlDoc.CreateElement("CubeRenderComponent");
                }
                else if (nodeType == "Sphere")
                {
                    renderComponent = xmlDoc.CreateElement("SphereRenderComponent");
                }
                else if (nodeType == "Cylinder")
                {
                    renderComponent = xmlDoc.CreateElement("CylinderRenderComponent");
                }
                else if (nodeType == "Teapot")
                {
                    renderComponent = xmlDoc.CreateElement("TeapotRenderComponent");
                }

                XmlElement effect = xmlDoc.CreateElement("Effect");
                renderComponent.AppendChild(effect);
                effect.InnerText = effectNode.Attributes["object"].Value;
                effect.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "technique", "main11"));
                effect.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "pass", "p0"));
                xmlActor.AppendChild(renderComponent);

                RenderMethods.ModifyActor(xmlActor.OuterXml);
            });

            RenderMethods.SetMoveDelegate(m_DllMoveDelegate);

            EnableControlView(true);
        }
Exemple #22
0
        private void OpenProject(string project)
        {
            RenderMethods.OpenProject(project);
            m_ProjectLocation = Path.GetDirectoryName(project);

            m_ProjectView.UpdateProject(project, selectedNode =>
            {
                if (m_PropertiesView.UpdateProjectProperties(selectedNode))
                {
                    int selectAcotrId = m_ProjectView.GetSelectActorId();
                    if (selectAcotrId > 2)
                    {
                        RenderMethods.SetPickedActor((uint)selectAcotrId);
                    }
                    else
                    {
                        RenderMethods.SetPickedActor(0);
                    }
                }
                else
                {
                    RenderMethods.SetPickedActor(0);
                }
            });

            string assetFile = m_ProjectLocation + @"\" + Path.GetFileNameWithoutExtension(project) + ".asset";

            m_AssetsView.UpdateAssets(assetFile, m_PropertiesView.UpdateAssetProperties, m_outputView.UpdateCompileInfo,
                                      effectNode =>
            {
                panelAllView.ActiveDocumentPane.ActiveContent = m_EditorView;
                m_EditorView.ShowEffectDoc(effectNode, m_ProjectLocation);
            },
                                      m_MaterialView);

            m_PropertiesView.ProjectLocation = m_ProjectLocation;
            m_PropertiesView.SetMoveActorDelegate(
                (string component, string attribute, Inspector.Vector3 value) =>
            {
                int actorId = m_ProjectView.GetSelectActorId();

                XmlDocument xmlDoc  = new XmlDocument();
                XmlElement xmlActor = xmlDoc.CreateElement("Actor");

                xmlActor.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "id", (actorId > 2 ? actorId : 0).ToString()));

                XmlElement transformComponent = xmlDoc.CreateElement(component);;
                XmlElement transformType      = xmlDoc.CreateElement(attribute);
                transformComponent.AppendChild(transformType);
                transformType.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "x", value.X.ToString()));
                transformType.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "y", value.Y.ToString()));
                transformType.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "z", value.Z.ToString()));
                xmlActor.AppendChild(transformComponent);

                RenderMethods.ModifyActor(xmlActor.OuterXml);
            },
                (string name, string value) =>
            {
                m_AssetsView.ModifyMaterial(name, value);
            }
                );

            m_RenderView.SetChangeMaterialDelegate((name, actorId, mesh) =>
            {
                m_ProjectView.SelectActorNode(actorId);
                XmlNode actorNode = m_ProjectView.GetSelectActorXml();

                XmlDocument xmlDoc  = new XmlDocument();
                XmlElement xmlActor = xmlDoc.CreateElement("Actor");

                xmlActor.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "id", actorId.ToString()));

                XmlElement material = xmlDoc.CreateElement("Material");
                material.InnerText  = @"Materials\" + Path.GetFileName(name);

                XmlElement renderComponent = null;
                string nodeType            = actorNode.Attributes["type"].Value;
                if (nodeType == "Model")
                {
                    renderComponent = xmlDoc.CreateElement("ModelRenderComponent");
                    material.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "index", mesh.ToString()));
                    XmlElement materials = xmlDoc.CreateElement("Materials");
                    materials.AppendChild(material);
                    renderComponent.AppendChild(materials);
                }
                else if (nodeType == "Plane")
                {
                    renderComponent = xmlDoc.CreateElement("PlaneRenderComponent");
                    renderComponent.AppendChild(material);
                }
                else if (nodeType == "Sphere")
                {
                    renderComponent = xmlDoc.CreateElement("SphereRenderComponent");
                    renderComponent.AppendChild(material);
                }
                else if (nodeType == "Torus")
                {
                    renderComponent = xmlDoc.CreateElement("TorusRenderComponent");
                    renderComponent.AppendChild(material);
                }
                else if (nodeType == "Teapot")
                {
                    renderComponent = xmlDoc.CreateElement("TeapotRenderComponent");
                    renderComponent.AppendChild(material);
                }

                xmlActor.AppendChild(renderComponent);

                RenderMethods.ModifyActor(xmlActor.OuterXml);
                m_ProjectView.ModifyMaterialXml((int)actorId, mesh, material.InnerText);
            });

            RenderMethods.SetMoveDelegate(m_DllMoveDelegate);

            EnableControlView(true);
        }