void translateVertex(VertexProp vertex, float[] translateData) { vertex.X += translateData[0]; vertex.Y += translateData[1]; vertex.Z += translateData[2]; }
private void button1_Click(object sender, EventArgs e) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Choose File"; openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "obj files (*.obj)|*.obj|All files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; ObjFigure objFigure = new ObjFigure(); ObjToStlConverter convertFigure = new ObjToStlConverter(); List <string[]> facets = new List <string[]>(); List <string[]> options = new List <string[]>(); StlWriter stlObjWriter = new StlWriter(); VertexProp verteces; VertexProp vertecesNormals; VertexProp vertecesTextures; //checks scale values if (byXtext.Text != null && byXtext.Text != "") { scaleX = float.Parse(byXtext.Text); } if (byYtext.Text != null && byYtext.Text != "") { scaleY = float.Parse(byYtext.Text); } if (byZtext.Text != null && byZtext.Text != "") { scaleZ = float.Parse(byZtext.Text); } //checks translate values if (trnsByXtext.Text != null && trnsByXtext.Text != "") { translateX = float.Parse(trnsByXtext.Text); } if (trnsByYtext.Text != null && trnsByYtext.Text != "") { translateY = float.Parse(trnsByYtext.Text); } if (trnsByZtext.Text != null && trnsByZtext.Text != "") { translateZ = float.Parse(trnsByZtext.Text); } scaleByXYZ = new float[] { scaleX, scaleY, scaleZ }; trnsByXYZ = new float[] { translateX, translateY, translateZ }; if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath; float x, y, z; string line; filePath = openFileDialog.FileName; StreamReader file = new StreamReader(filePath); while ((line = file.ReadLine()) != null) { string[] propList = line.Split(' '); switch (propList[0]) { case "v": x = float.Parse(propList[1]); y = float.Parse(propList[2]); z = float.Parse(propList[3]); verteces = new VertexProp(x, y, z); scaleVertex(verteces, scaleByXYZ); translateVertex(verteces, trnsByXYZ); objFigure.Verteces.Add(verteces); break; case "vt": if (propList.Count() == 2) { x = float.Parse(propList[1]); vertecesTextures = new VertexProp(x); objFigure.VertecesTextures.Add(vertecesTextures); } else if (propList.Count() == 3) { x = float.Parse(propList[1]); y = float.Parse(propList[2]); vertecesTextures = new VertexProp(x, y); objFigure.VertecesTextures.Add(vertecesTextures); } else { x = float.Parse(propList[1]); y = float.Parse(propList[2]); z = float.Parse(propList[3]); vertecesTextures = new VertexProp(x, y, z); objFigure.VertecesTextures.Add(vertecesTextures); } break; case "vn": x = float.Parse(propList[1]); y = float.Parse(propList[2]); z = float.Parse(propList[3]); vertecesNormals = new VertexProp(x, y, z); objFigure.VertecesNormals.Add(vertecesNormals); break; case "f": facets.Add(propList); convertFigure.facetCalculation(propList); break; } } stlObjWriter.writeHeader(convertFigure.NumberOfFacets); foreach (string[] element in facets) { var tuple = convertFigure.convertFromTo(objFigure, element, scaleByXYZ, trnsByXYZ); totalArea += tuple.Item1; totalVolume += tuple.Item2; } MessageBox.Show("The work is done", "", MessageBoxButtons.OK); areaText.Text = totalArea.ToString(); volumeText.Text = totalVolume.ToString(); convertFrom.Text = ""; convertTo.Text = ""; convertTo.Enabled = false; button1.Enabled = false; } }
void scaleVertex(VertexProp vertex, float[] scaleData) { vertex.X *= scaleData[0]; vertex.Y *= scaleData[1]; vertex.Z *= scaleData[2]; }