Exemplo n.º 1
0
        /// <summary>
        /// Método que se llama cuando se quiere exportar la informacion de la escena a un XML.
        ///
        ///
        /// MODIFICAR ESTA SECCION PARA ADAPTARSE A LAS NECESIDADES DEL ALUMNO
        ///
        ///
        ///
        /// </summary>
        internal void exportScene(string savePath)
        {
            //Crea XML
            XmlDocument doc  = new XmlDocument();
            XmlNode     root = doc.CreateElement("SceneEditor-Export");

            //Guardar info del terreno
            XmlElement       terrainNode = doc.CreateElement("Terrain");
            TgcSimpleTerrain terrain     = modifier.EditorControl.TgcTerrain;

            if (terrain != null)
            {
                terrainNode.SetAttribute("enable", true.ToString());
                terrainNode.SetAttribute("heightmap", modifier.EditorControl.heighmap.Text);
                terrainNode.SetAttribute("texture", modifier.EditorControl.terrainTexture.Text);
                terrainNode.SetAttribute("xzScale", modifier.EditorControl.terrainXZscale.Value.ToString());
                terrainNode.SetAttribute("yScale", modifier.EditorControl.terrainYscale.Value.ToString());
                terrainNode.SetAttribute("center", TgcParserUtils.printVector3FromString(
                                             modifier.EditorControl.terrainCenterX.Text,
                                             modifier.EditorControl.terrainCenterY.Text,
                                             modifier.EditorControl.terrainCenterZ.Text));
            }
            else
            {
                terrainNode.SetAttribute("enable", false.ToString());
            }
            root.AppendChild(terrainNode);


            //Recorrer Meshes del escenario, ordenadas por grupo
            List <SceneEditorMeshObject> meshObjects = modifier.EditorControl.getMeshObjectsOrderByGroup();
            XmlElement meshesNode    = doc.CreateElement("Meshes");
            int        groupIndex    = -1;
            XmlElement lastGroupNode = null;

            foreach (SceneEditorMeshObject meshObject in meshObjects)
            {
                //Crear grupo con corte de control
                if (meshObject.groupIndex > groupIndex)
                {
                    groupIndex    = meshObject.groupIndex;
                    lastGroupNode = doc.CreateElement("MeshGroup");
                    lastGroupNode.SetAttribute("groupIndex", groupIndex.ToString());
                    meshesNode.AppendChild(lastGroupNode);
                }

                //Guardar info de mesh
                TgcMesh    mesh     = meshObject.mesh;
                XmlElement meshNode = doc.CreateElement("Mesh");
                meshNode.SetAttribute("name", meshObject.name);
                meshNode.SetAttribute("index", meshObject.index.ToString());
                meshNode.SetAttribute("file", meshObject.fileName);
                meshNode.SetAttribute("folder", meshObject.folderName);
                meshNode.SetAttribute("position", TgcParserUtils.printVector3(mesh.Position));
                meshNode.SetAttribute("rotation", TgcParserUtils.printVector3(mesh.Rotation));
                meshNode.SetAttribute("scale", TgcParserUtils.printVector3(mesh.Scale));
                meshNode.SetAttribute("userInfo", meshObject.userInfo);

                lastGroupNode.AppendChild(meshNode);
            }
            root.AppendChild(meshesNode);


            //Guardar XML
            doc.AppendChild(root);
            doc.Save(savePath);
        }