Пример #1
0
        public static XmlElement CreateSphereRenderComponent(XmlDocument xmlDoc)
        {
            XmlElement sphereElement = xmlDoc.CreateElement("SphereRenderComponent");

            XmlElement sphere = xmlDoc.CreateElement("Sphere");
            XmlElement effect = xmlDoc.CreateElement("Material");

            sphereElement.AppendChild(sphere);
            sphereElement.AppendChild(effect);

            effect.InnerText = @"Materials\DefaultMaterial.mat";

            sphere.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "diameter", "1.0"));
            sphere.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "tessellation", "4"));
            sphere.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "rhcoords", "1"));

            return(sphereElement);
        }
Пример #2
0
        public static XmlElement CreateTorusRenderComponent(XmlDocument xmlDoc)
        {
            XmlElement torusElement = xmlDoc.CreateElement("TorusRenderComponent");

            XmlElement torus  = xmlDoc.CreateElement("Torus");
            XmlElement effect = xmlDoc.CreateElement("Material");

            torusElement.AppendChild(torus);
            torusElement.AppendChild(effect);

            effect.InnerText = @"Materials\DefaultMaterial.mat";

            torus.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "diameter", "0.8"));
            torus.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "thickness", "0.4"));
            torus.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "tessellation", "32"));
            torus.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "rhcoords", "1"));

            return(torusElement);
        }
Пример #3
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);
                    }
                }
            }
        }
Пример #4
0
        private XmlNode CreateProjectXmlNode(XmlNode node, string projectLocation)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement projectElement = xmlDoc.CreateElement("Project");

            projectElement.Attributes.Append(XmlUtility.CreateAttribute(xmlDoc, "type", "Project"));

            XmlNode name = xmlDoc.CreateElement("Name");

            name.InnerText = Path.GetFileNameWithoutExtension(projectLocation);

            XmlNode location = xmlDoc.CreateElement("Location");

            location.InnerText = projectLocation;

            projectElement.AppendChild(name);
            projectElement.AppendChild(location);

            return(projectElement);
        }
Пример #5
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);
        }
Пример #6
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);
        }