public async static Task <Grendgine_Collada> Grendgine_Load_File()
        {
            try
            {
                Grendgine_Collada col_scenes = null;
                XmlSerializer     sr         = new XmlSerializer(typeof(Grendgine_Collada));
                FileOpenPicker    openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                openPicker.FileTypeFilter.Add(".xml");
                openPicker.FileTypeFilter.Add(".dae");
                StorageFile file = await openPicker.PickSingleFileAsync();

                if (file != null)
                {
                    var stream = await file.OpenStreamForReadAsync();

                    col_scenes = (Grendgine_Collada)(sr.Deserialize(stream));
                }

                return(col_scenes);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.ToString());
                //Console.ReadLine();
                return(null);
            }
        }
Exemple #2
0
        public static void Grendgine_Save_File(string file_name, Grendgine_Collada col_scene)
        {
            XmlSerializer sr = new XmlSerializer(typeof(Grendgine_Collada));
            TextWriter    tr = new StreamWriter(file_name);

            sr.Serialize(tr, col_scene);
            tr.Close();
        }
Exemple #3
0
        public static string Grendgine_Load_String(string docStr, out Grendgine_Collada outDoc)
        {
            outDoc = null;
            try
            {
                XmlSerializer sr = new XmlSerializer(typeof(Grendgine_Collada));
                TextReader    tr = new StringReader(docStr);
                outDoc = (Grendgine_Collada)(sr.Deserialize(tr));

                tr.Close();

                return(string.Empty);
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
        public static Grendgine_Collada Save(string file_name, Grendgine_Collada col_scenes)
        {
            try
            {
                string path = OpenTKExtension.IOUtils.ExtractDirectory(file_name);

                TextWriter    tw = new StreamWriter(path + "new.dae");
                XmlSerializer sr = new XmlSerializer(typeof(Grendgine_Collada));
                sr.Serialize(tw, col_scenes);
                tw.Close();
                return(col_scenes);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error in Save: " + ex.Message);
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                return(null);
            }
        }
        public static Grendgine_Collada Grendgine_Load_File(string file_name)
        {
            try
            {
                Grendgine_Collada col_scenes = null;

                XmlSerializer sr = new XmlSerializer(typeof(Grendgine_Collada));
                TextReader    tr = new StreamReader(file_name);
                col_scenes = (Grendgine_Collada)(sr.Deserialize(tr));

                tr.Close();

                return(col_scenes);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                return(null);
            }
        }
        public async static void Grendgine_Save_File(Grendgine_Collada data)
        {
            FileSavePicker savePicker = new FileSavePicker();

            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("DAE", new List <string>()
            {
                ".dae"
            });
            savePicker.FileTypeChoices.Add("Xml", new List <string>()
            {
                ".xml"
            });

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "Test";

            StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                IRandomAccessStream sessionRandomAccess = await file.OpenAsync(FileAccessMode.ReadWrite);

                IOutputStream sessionOutputStream = sessionRandomAccess.GetOutputStreamAt(0);
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Grendgine_Collada));
                    serializer.Serialize(sessionOutputStream.AsStreamForWrite(), data);
                }
                catch (System.InvalidOperationException e)
                {
                    Debug.WriteLine(e.InnerException);
                }
                sessionRandomAccess.Dispose();
                await sessionOutputStream.FlushAsync();

                sessionOutputStream.Dispose();
            }
        }
        public static Grendgine_Collada Load_File(string file_name)
        {
            try
            {
                Grendgine_Collada col_scenes = null;

                XmlSerializer sr = new XmlSerializer(typeof(Grendgine_Collada));
                TextReader    tr = new StreamReader(file_name);
                col_scenes = (Grendgine_Collada)(sr.Deserialize(tr));

                tr.Close();

                return(col_scenes);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error in Load_File: " + ex.Message);
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                return(null);
            }
        }
Exemple #8
0
        public async static void Grendgine_Save_File(Grendgine_Collada data)
        {
            FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("DAE", new List<string>() { ".dae" });
            savePicker.FileTypeChoices.Add("Xml", new List<string>() { ".xml" });
            
            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "Test";

            StorageFile file = await savePicker.PickSaveFileAsync();
            if (file != null)
            {
                IRandomAccessStream sessionRandomAccess = await file.OpenAsync(FileAccessMode.ReadWrite);
                IOutputStream sessionOutputStream = sessionRandomAccess.GetOutputStreamAt(0);
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Grendgine_Collada));
                    serializer.Serialize(sessionOutputStream.AsStreamForWrite(), data);
                }
                catch (System.InvalidOperationException e)
                {
                    Debug.WriteLine(e.InnerException);
                }
                sessionRandomAccess.Dispose();
                await sessionOutputStream.FlushAsync();
                sessionOutputStream.Dispose();
            }
        }
        public static bool ReduceMesh(string file_name, float factor)
        {
            bool b = true;

            if (b)
            {
                System.Diagnostics.Debug.WriteLine("sds");
            }

            //removeEveryNth hast to be < 1
            if (factor >= 1)
            {
                System.Windows.Forms.MessageBox.Show("SW Error reducing mesh - reduce factor has to be less than 1");
            }
            try
            {
                Grendgine_Collada col = Grendgine_Collada.Load_File(file_name);


                if (col.Library_Geometries != null)
                {
                    if (col.Library_Geometries.Geometry != null)
                    {
                        for (int i = 0; i < col.Library_Geometries.Geometry.Length; i++)
                        {
                            Grendgine_Collada_Geometry geo = col.Library_Geometries.Geometry[i];
                            if (geo.Mesh != null)
                            {
                                if (geo.Mesh.Triangles != null)
                                {
                                    if (geo.Mesh.Triangles != null)
                                    {
                                        for (int j = 0; j < geo.Mesh.Triangles.Length; j++)
                                        {
                                            Grendgine_Collada_Triangles triangles = geo.Mesh.Triangles[j];
                                            if (triangles.P != null && triangles.P.Value_As_String != null)
                                            {
                                                string triangleString = triangles.P.Value_As_String;
                                                int    newCount;
                                                string newTriangles = OpenTKExtension.IOUtils.ReduceTriangles(triangleString, factor, out newCount);
                                                triangles.P.Value_As_String = newTriangles;
                                                triangles.Count             = newCount;
                                                col.Library_Geometries.Geometry[i].Mesh.Triangles[j].P.Value_As_String = newTriangles;

                                                System.Diagnostics.Debug.Write(triangleString);

                                                System.Diagnostics.Debug.Write(newTriangles);
                                            }
                                            else
                                            {
                                                System.Diagnostics.Debug.Write("CHECK");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                string path = OpenTKExtension.IOUtils.ExtractDirectory(file_name);
                Grendgine_Collada.Save(path + "new.dae", col);


                return(true);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error in Save: " + ex.Message);
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                return(false);
            }
        }