Example #1
0
        public void ParseSave(WaveFront wave, Rescale rescale, string fileName)
        {
            var linesFinal = new List <string>();

            foreach (var line in wave.Original)
            {
                if (line == "")
                {
                    linesFinal.Add(line);
                    continue;
                }
                if (line.Substring(0, 1) == "#")
                {
                    // add comments.
                    linesFinal.Add(line);
                    continue;
                }
                var cont  = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var first = cont[0];
                switch (first)
                {
                case "o":
                case "g":
                case "\0":
                case "mtllib":
                case "usemtl":
                case "s":
                case "f":
                case "vt":
                    linesFinal.Add(line);     // we do nothing
                    break;

                case "v":
                    linesFinal.Add(AddVector(cont, rescale));
                    //AddVector(waveFront, line);
                    break;

                case "vn":
                    linesFinal.Add(AddNormal(cont, rescale));
                    //waveFront.vn.Add(second);
                    break;

                default:
                    throw new Exception("Error in group type :[" + first + "]");
                }
            }

            string txt = String.Join("\r\n", linesFinal);

            File.WriteAllText(fileName, txt);
        }
Example #2
0
        private void buttonResize_Click(object sender, EventArgs e)
        {
            if (_waveFront == null)
            {
                MessageBox.Show("You must load a OBJ first");
                return;
            }
            FormResize fr = new FormResize();

            // recover backup
            _waveFront.V = objSrv.CloneList(_waveFront.VBackup);
            objSrv.ObjGetStat(_waveFront);

            fr.WaveFront = _waveFront;
            fr.rescale   = _rescale;
            fr.ShowDialog();

            if (!fr.ok)
            {
                _rescale = new Rescale(); // reset rescale
                return;                   // operation cancelled.
            }

            ShowMsg("Calculating");

            // rescale
            var newList = new List <Vector>();

            for (var i = 0; i < _waveFront.V.Count; i++)
            {
                var v = _waveFront.V[i];
                newList.Add(_rescale.Modify(v));
            }

            _waveFront.V = newList; // changed the list
            ShowMsg("Drawing...");
            objSrv.ObjGetStat(_waveFront);
            DrawStat();
            var scale = objSrv.Scale(_waveFront.Max, _waveFront.Min, panel1.Width, panel1.Height, 0);
            int axis  = comboBox1.SelectedIndex;

            _bitmap = objDraw.Draw(_waveFront, panel1.Width, panel1.Height, scale, axis);
            panel1.Refresh();
            HideMsg();
            fr.Close();
        }
Example #3
0
        private string AddNormal(string[] line, Rescale r)
        {
            if (line.Length < 4)
            {
                //error, vector incorrectly defined.
                throw new Exception("Error in vector");
            }


            Vector vector = new Vector(double.Parse(line[1], culture)
                                       , double.Parse(line[2], culture)
                                       , double.Parse(line[3], culture));

            vector = r.ModifyNormal(vector);
            return("vn " + vector.X.ToString("0.########", culture) + " "
                   + vector.Y.ToString("0.########", culture) + " "
                   + vector.Z.ToString("0.########", culture));
        }