Esempio n. 1
0
        /// <summary>
        /// This function saves the current model with all its modifications and resets the modification
        /// parameters
        /// <returns>The path of the newly created file</returns>
        /// </summary>
        public string saveModelandReset()
        {
            //Save the current model to a file
            var newFilePath = Values.currentStlFile.Replace(".stl", "_mod.stl");

            StlExporter.exportStlToFile(vertexList, newFilePath);

            //Reset the modifiers
            modelXRot   = 0;
            modelYRot   = 0;
            modelZRot   = 0;
            objectScale = 1;
            //modelXOffset = 0;
            //modelYOffset = 0;

            return(newFilePath);
        }
Esempio n. 2
0
        /// <summary>
        /// This method converts a given ascii stl file to a binary one
        /// </summary>
        /// <param name="filePath">The path of the ascii file to convert</param>
        public static void convertAsciiToBinary(string filePath)
        {
            IsolatedStorageFile       isf    = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath, FileMode.OpenOrCreate, isf);
            StreamReader streamReader        = new StreamReader(stream);//filePath);

            string readLine = "";

            List <Vector3> p1List = new List <Vector3>();
            List <Vector3> p2List = new List <Vector3>();
            List <Vector3> p3List = new List <Vector3>();
            List <Vector3> nList  = new List <Vector3>();

            List <VertexPositionColoredNormal> vertexList = new List <VertexPositionColoredNormal>();

            Vector3 p1, p2, p3, n;

            string[] lineElements;

            float v1, v2, v3;

            while (!streamReader.EndOfStream && Values.stl_IsBusy)
            {
                readLine = streamReader.ReadLine();

                if (readLine.Contains("facet normal"))
                {
                    try
                    {
                        readLine     = readLine.Replace(@"facet normal ", " ");                                //remove the word "facet normal" from the line
                        lineElements = readLine.Split(' ');                                                    //split the line at each space
                        //the first 7 segments are just empty characters
                        v1 = float.Parse(lineElements[lineElements.Length - 3], CultureInfo.InvariantCulture); //We need to use US formatting because the strings
                        v2 = float.Parse(lineElements[lineElements.Length - 2], CultureInfo.InvariantCulture); //contain "."s which represent the decimal points
                        v3 = float.Parse(lineElements[lineElements.Length - 1], CultureInfo.InvariantCulture);
                        n  = new Vector3(v1, v2, v3);                                                          //store the vertex value

                        streamReader.ReadLine();                                                               //Skip the "outer loop" line

                        readLine     = streamReader.ReadLine();
                        readLine     = readLine.Replace(@"vertex", " ");                                       //remove the word "vertex" from the line
                        lineElements = readLine.Split(' ');                                                    //split the line at each space
                        //the first 7 segments are just empty characters
                        v1 = float.Parse(lineElements[lineElements.Length - 3], CultureInfo.InvariantCulture); //We need to use US formatting because the strings
                        v2 = float.Parse(lineElements[lineElements.Length - 2], CultureInfo.InvariantCulture); //contain "."s which represent the decimal points
                        v3 = float.Parse(lineElements[lineElements.Length - 1], CultureInfo.InvariantCulture);
                        p1 = new Vector3(v1, v2, v3);                                                          //store the vertex value
                        vertexList.Add(new VertexPositionColoredNormal(p1, new Color(), n));

                        readLine     = streamReader.ReadLine();
                        readLine     = readLine.Replace(@"vertex", " ");                                       //remove the word "vertex" from the line
                        lineElements = readLine.Split(' ');                                                    //split the line at each space
                        //the first 7 segments are just empty characters
                        v1 = float.Parse(lineElements[lineElements.Length - 3], CultureInfo.InvariantCulture); //We need to use US formatting because the strings
                        v2 = float.Parse(lineElements[lineElements.Length - 2], CultureInfo.InvariantCulture); //contain "."s which represent the decimal points
                        v3 = float.Parse(lineElements[lineElements.Length - 1], CultureInfo.InvariantCulture);
                        p2 = new Vector3(v1, v2, v3);                                                          //store the vertex value
                        vertexList.Add(new VertexPositionColoredNormal(p2, new Color(), n));

                        readLine     = streamReader.ReadLine();
                        readLine     = readLine.Replace(@"vertex", " ");                                       //remove the word "vertex" from the line
                        lineElements = readLine.Split(' ');                                                    //split the line at each space
                        //the first 7 segments are just empty characters
                        v1 = float.Parse(lineElements[lineElements.Length - 3], CultureInfo.InvariantCulture); //We need to use US formatting because the strings
                        v2 = float.Parse(lineElements[lineElements.Length - 2], CultureInfo.InvariantCulture); //contain "."s which represent the decimal points
                        v3 = float.Parse(lineElements[lineElements.Length - 1], CultureInfo.InvariantCulture);
                        p3 = new Vector3(v1, v2, v3);                                                          //store the vertex value
                        vertexList.Add(new VertexPositionColoredNormal(p3, new Color(), n));
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                }
            }

            streamReader.Dispose();
            stream.Dispose();

            //Stop here if we need to stop loading
            if (!Values.stl_IsBusy)
            {
                return;
            }

            //Now that we have the list of vertices we can export them to the file in binary format.
            StlExporter.exportStlToFile(vertexList, filePath);
        }