public static bool SettingsSave( string output, MainForm.EConvOption econvOption, bool checked3, double _Scalar, float num2, int num1, string text3, string str1, string str2, string text1, bool axis) { XElement settings = new XElement("OBJ2MAPSettings", new XElement("MAPOutput", @output), new XElement("BrushMethod", @econvOption.ToString()), new XElement("CopyToClipboard", @checked3.ToString()), new XElement("Depth", @_Scalar), new XElement("Scale", @num2), new XElement("DecimalPlaces", @num1), new XElement("Class", @text3), new XElement("VisibleTexture", @str1), new XElement("HiddenTexture", @str2), new XElement("AxisAligned", @axis.ToString()) ); settings.Save(Path.Combine(Path.GetDirectoryName(text1), Path.GetFileNameWithoutExtension(text1) + ".xml")); string test = text3.ToString(); return(true); }
public static void AddBrushesToMAP(MainForm _MainForm, MainForm.EConvOption econvOption, List <XVector> _Vertices, List <XFace> _Faces, List <XBrush> _Brushes, string format, ref string _MAPText, string _VisibleTextureName, string _HiddenTextureName, double _Scalar ) { _MainForm.UpdateProgress("Adding Brushes to MAP..."); int BrushCount = 0; switch (econvOption) { case MainForm.EConvOption.Extrusion: using (List <XBrush> .Enumerator enumerator = _Brushes.GetEnumerator()) { while (enumerator.MoveNext()) { _MainForm.UpdateProgress(string.Format("Adding Brush {0:n0} to MAP...", BrushCount++)); foreach (XFace xface in enumerator.Current.Faces) { XVector _B = XVector.Multiply(xface.Normal, _Scalar); List <XVector> list3 = new List <XVector>(); List <XVector> list4 = new List <XVector>(); foreach (int index in xface.VertIdx) { XVector _A = new XVector(_Vertices[index]); list3.Add(_A); list4.Add(XVector.Add(_A, _B)); } _MAPText += "{\n"; XVector xvector1 = list3[0]; XVector xvector2 = list3[1]; XVector xvector3 = list3[2]; _MAPText += string.Format("\t( {0} {1} {2} ) ", (object)xvector1.x.ToString(format, new CultureInfo("en-US")), (object)xvector1.y.ToString(format, new CultureInfo("en-US")), (object)xvector1.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) ", (object)xvector3.x.ToString(format, new CultureInfo("en-US")), (object)xvector3.y.ToString(format, new CultureInfo("en-US")), (object)xvector3.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) {3} 0 0 0 1 1\n", (object)xvector2.x.ToString(format, new CultureInfo("en-US")), (object)xvector2.y.ToString(format, new CultureInfo("en-US")), (object)xvector2.z.ToString(format, new CultureInfo("en-US")), (object)_VisibleTextureName); XVector xvector4 = list4[2]; XVector xvector5 = list4[1]; XVector xvector6 = list4[0]; _MAPText += string.Format("\t( {0} {1} {2} ) ", (object)xvector4.x.ToString(format, new CultureInfo("en-US")), (object)xvector4.y.ToString(format, new CultureInfo("en-US")), (object)xvector4.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) ", (object)xvector6.x.ToString(format, new CultureInfo("en-US")), (object)xvector6.y.ToString(format, new CultureInfo("en-US")), (object)xvector6.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) {3} 0 0 0 1 1\n", (object)xvector5.x.ToString(format, new CultureInfo("en-US")), (object)xvector5.y.ToString(format, new CultureInfo("en-US")), (object)xvector5.z.ToString(format, new CultureInfo("en-US")), (object)_HiddenTextureName); for (int index = 0; index < list3.Count; ++index) { XVector xvector7 = list3[index]; XVector xvector8 = list3[(index + 1) % list3.Count]; XVector xvector9 = list4[index]; _MAPText += string.Format("\t( {0} {1} {2} ) ", (object)xvector7.x.ToString(format, new CultureInfo("en-US")), (object)xvector7.y.ToString(format, new CultureInfo("en-US")), (object)xvector7.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) ", (object)xvector8.x.ToString(format, new CultureInfo("en-US")), (object)xvector8.y.ToString(format, new CultureInfo("en-US")), (object)xvector8.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) {3} 0 0 0 1 1\n", (object)xvector9.x.ToString(format, new CultureInfo("en-US")), (object)xvector9.y.ToString(format, new CultureInfo("en-US")), (object)xvector9.z.ToString(format, new CultureInfo("en-US")), (object)_HiddenTextureName); } _MAPText += "}\n"; } } break; } case MainForm.EConvOption.Spikes: using (List <XBrush> .Enumerator enumerator = _Brushes.GetEnumerator()) { while (enumerator.MoveNext()) { _MainForm.UpdateProgress(string.Format("Adding Brush {0:n0} to MAP...", BrushCount++)); foreach (XFace xface in enumerator.Current.Faces) { XVector _B1 = XVector.Multiply(xface.Normal, _Scalar); List <XVector> list3 = new List <XVector>(); foreach (int index in xface.VertIdx) { XVector xvector = new XVector(_Vertices[index]); list3.Add(xvector); } _MAPText += "{\n"; XVector xvector1 = list3[0]; XVector xvector2 = list3[1]; XVector xvector3 = list3[2]; _MAPText += string.Format("\t( {0} {1} {2} ) ", (object)xvector1.x.ToString(format, new CultureInfo("en-US")), (object)xvector1.y.ToString(format, new CultureInfo("en-US")), (object)xvector1.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) ", (object)xvector3.x.ToString(format, new CultureInfo("en-US")), (object)xvector3.y.ToString(format, new CultureInfo("en-US")), (object)xvector3.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) {3} 0 0 0 1 1\n", (object)xvector2.x.ToString(format, new CultureInfo("en-US")), (object)xvector2.y.ToString(format, new CultureInfo("en-US")), (object)xvector2.z.ToString(format, new CultureInfo("en-US")), (object)_VisibleTextureName); XVector xvector4 = new XVector(); foreach (int index in xface.VertIdx) { XVector _B2 = new XVector(_Vertices[index]); xvector4 = XVector.Add(xvector4, _B2); } XVector xvector5 = XVector.Add(XVector.Divide(xvector4, (double)xface.VertIdx.Count), _B1); for (int index = 0; index < list3.Count; ++index) { XVector xvector6 = list3[index]; XVector xvector7 = list3[(index + 1) % list3.Count]; _MAPText += string.Format("\t( {0} {1} {2} ) ", (object)xvector5.x.ToString(format, new CultureInfo("en-US")), (object)xvector5.y.ToString(format, new CultureInfo("en-US")), (object)xvector5.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) ", (object)xvector6.x.ToString(format, new CultureInfo("en-US")), (object)xvector6.y.ToString(format, new CultureInfo("en-US")), (object)xvector6.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) {3} 0 0 0 1 1\n", (object)xvector7.x.ToString(format, new CultureInfo("en-US")), (object)xvector7.y.ToString(format, new CultureInfo("en-US")), (object)xvector7.z.ToString(format, new CultureInfo("en-US")), (object)_HiddenTextureName); } _MAPText += "}\n"; } } break; } default: using (List <XBrush> .Enumerator enumerator = _Brushes.GetEnumerator()) { while (enumerator.MoveNext()) { XBrush current = enumerator.Current; _MAPText += "{\n"; _MainForm.UpdateProgress(string.Format("Adding Brush {0:n0} to MAP...", BrushCount++)); foreach (XFace xface in current.Faces) { XVector xvector1 = _Vertices[xface.VertIdx[0]]; XVector xvector2 = _Vertices[xface.VertIdx[2]]; XVector xvector3 = _Vertices[xface.VertIdx[1]]; _MAPText += string.Format("\t( {0} {1} {2} ) ", (object)xvector1.x.ToString(format, new CultureInfo("en-US")), (object)xvector1.y.ToString(format, new CultureInfo("en-US")), (object)xvector1.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) ", (object)xvector2.x.ToString(format, new CultureInfo("en-US")), (object)xvector2.y.ToString(format, new CultureInfo("en-US")), (object)xvector2.z.ToString(format, new CultureInfo("en-US"))); _MAPText += string.Format("( {0} {1} {2} ) {3} 0 0 0 1 1\n", (object)xvector3.x.ToString(format, new CultureInfo("en-US")), (object)xvector3.y.ToString(format, new CultureInfo("en-US")), (object)xvector3.z.ToString(format, new CultureInfo("en-US")), (object)_VisibleTextureName); } _MAPText += "}\n"; } break; } } }
private void GoButton_Click(object sender, EventArgs e) { List <bool> SavedCtrlStates = new List <bool>(); foreach (Control C in Controls) { SavedCtrlStates.Add(C.Enabled); C.Enabled = false; } ProgressBar.Enabled = true; ProgressLabel.Enabled = true; ProgressLabel.Show(); ProgressBar.Show(); GOButton.Hide(); UpdateProgress("Initializing..."); string OBJFilename = this.OBJFilename.Text; string MAPFilename = this.MAPFilename.Text; MainForm.EConvOption econvOption = MainForm.EConvOption.Standard; if (this.RB_Extrusion.Checked) { econvOption = MainForm.EConvOption.Extrusion; } else if (this.RB_Spikes.Checked) { econvOption = MainForm.EConvOption.Spikes; } double Depth = double.Parse(this.DepthTextBox.Text); bool bAxisAligned = this.AxisAlignedCheckBox.Checked; int NumDecimals = Math.Max(int.Parse(this.DecimalsTextBox.Text), 0); float ScaleFactor = float.Parse(this.ScaleTextBox.Text); string VisibleTextureName = VisibleTextureTextBox.Text.Length > 0 ? VisibleTextureTextBox.Text : "DEFAULT"; string HiddenTextureName = HiddenTextureTextBox.Text.Length > 0 ? HiddenTextureTextBox.Text : "SKIP"; bool bCopyToClipboard = this.CopyToClipboardCheck.Checked; string Classname = this.ClassTextBox.Text; StreamWriter LogFile = new StreamWriter("OBJ2MAP.log"); // Error checking if (!File.Exists(OBJFilename)) { int num3 = (int)MessageBox.Show("OBJ file doesn't exist."); } else if ((double)ScaleFactor <= 0.0) { int num4 = (int)MessageBox.Show("Scale needs to be above 0%."); } else if (econvOption != MainForm.EConvOption.Standard && Depth < 1.0) { int num5 = (int)MessageBox.Show("Depth must be greater than 0."); } else { // Input looks good, let's go... LogFile.AutoFlush = true; LogFile.WriteLine(">>> OBJ-2-MAP v1.1 starting up. <<<"); LogFile.WriteLine(string.Format("{0}", (object)DateTime.Now)); LogFile.WriteLine(string.Format("OBJ Filename : {0}", (object)OBJFilename)); StreamWriter streamWriter2 = (StreamWriter)null; if (MAPFilename.Length > 0) { streamWriter2 = File.CreateText(MAPFilename); LogFile.WriteLine(string.Format("MAP Filename : {0}", (object)MAPFilename)); } MainForm.EGRP egrp = MainForm.EGRP.Undefined; List <XVector> _Vertices = new List <XVector>(); List <XFace> list1 = new List <XFace>(); List <XBrush> list2 = new List <XBrush>(); char[] separator1 = new char[1] { ' ' }; char[] separator2 = new char[1] { '/' }; string format = string.Format("F{0}", (object)NumDecimals); LogFile.WriteLine(""); LogFile.WriteLine(string.Format("Method : {0}", (object)econvOption.ToString())); LogFile.WriteLine(string.Format("Copy To Clipboard : {0}", (object)bCopyToClipboard.ToString())); LogFile.WriteLine(string.Format("Depth: {0}", (object)Depth)); LogFile.WriteLine(string.Format("Scale: {0}", (object)ScaleFactor)); LogFile.WriteLine(string.Format("Decimal Places: {0}", (object)NumDecimals)); LogFile.WriteLine(string.Format("Class: {0}", Classname.Length > 0 ? (object)Classname : (object)"worldspawn")); LogFile.WriteLine(string.Format("Visible Texture: {0}", VisibleTextureName.Length > 0 ? (object)VisibleTextureName : (object)"DEFAULT")); LogFile.WriteLine(string.Format("Hidden Texture: {0}", HiddenTextureName.Length > 0 ? (object)HiddenTextureName : (object)"SKIP")); LogFile.WriteLine(""); LogFile.WriteLine("! Reading OBJ file into memory"); string[] fileLines = File.ReadAllLines(OBJFilename); MAPCreation.LoadOBJ(this, fileLines, egrp, LogFile, ref _Vertices, ref list1, ref list2, ScaleFactor, separator1, separator2); if (list1.Count > 0) { list2.Add(new XBrush() { Faces = list1 }); } LogFile.WriteLine(""); LogFile.WriteLine("Summary:"); LogFile.WriteLine(string.Format("Vertices: {0}", (object)_Vertices.Count)); LogFile.WriteLine(string.Format("Faces: {0}", (object)list1.Count)); LogFile.WriteLine(string.Format("Brushes: {0}", (object)list2.Count)); LogFile.WriteLine(""); LogFile.WriteLine("! Computing face normals."); foreach (XFace xface in list1) { UpdateProgress("Processing Faces..."); xface.ComputeNormal(ref _Vertices); if (bAxisAligned) { XVector[] AxisArray = new XVector[6] { new XVector(1.0, 0.0, 0.0), new XVector(-1.0, 0.0, 0.0), new XVector(0.0, 1.0, 0.0), new XVector(0.0, -1.0, 0.0), new XVector(0.0, 0.0, 1.0), new XVector(0.0, 0.0, -1.0) }; int index1 = -1; double num6 = -999.0; for (int index2 = 0; index2 < 6; ++index2) { double num7 = XVector.Dot(AxisArray[index2], xface.Normal); if (num7 > num6) { num6 = num7; index1 = index2; } } xface.Normal = AxisArray[index1]; } } LogFile.WriteLine("! Beginning MAP construction."); string str5 = "" + "{\n" + string.Format("\"classname\" \"{0}\"\n", Classname.Length > 0 ? (object)Classname : (object)"worldspawn"); // HACK: Fix for crash. foreach (var brush in list2) { foreach (var face in brush.Faces) { if (face.Normal == null) { face.ComputeNormal(ref _Vertices); } } } MAPCreation.AddBrushesToMAP(this, econvOption, _Vertices, list1, list2, format, ref str5, VisibleTextureName, HiddenTextureName, Depth); string text4 = str5 + "}\n"; if (streamWriter2 != null) { streamWriter2.Write(text4); streamWriter2.Close(); } if (bCopyToClipboard) { Clipboard.Clear(); Clipboard.SetText(text4); } SceneSettings.SettingsSave(this.MAPFilename.Text, econvOption, bCopyToClipboard, Depth, ScaleFactor, NumDecimals, Classname, VisibleTextureName, HiddenTextureName, OBJFilename, this.AxisAlignedCheckBox.Checked); } int SCSIdx = 0; foreach (Control C in Controls) { C.Enabled = SavedCtrlStates[SCSIdx++]; } UpdateProgress(" "); ProgressLabel.Hide(); ProgressBar.Hide(); GOButton.Show(); string str6 = "Done!" + "\n\n" + string.Format("\"{0}\" converted successfully.\n", (object)OBJFilename) + "\n"; if (MAPFilename.Length > 0) { str6 += string.Format("Written to \"{0}\"", (object)MAPFilename); } string FinishMsg = !bCopyToClipboard ? str6 + "." : (MAPFilename.Length <= 0 ? str6 + "MAP text copied to the clipboard." : str6 + "and MAP text copied to the clipboard."); LogFile.WriteLine(FinishMsg); MessageBox.Show(FinishMsg); LogFile.Close(); }