diff --git a/Source/Core/Data/DataManager.cs b/Source/Core/Data/DataManager.cs index 94a24485..4a926be8 100644 --- a/Source/Core/Data/DataManager.cs +++ b/Source/Core/Data/DataManager.cs @@ -512,7 +512,7 @@ namespace CodeImp.DoomBuilder.Data // Start a low priority thread to load images in background General.WriteLogLine("Starting background resource loading..."); - backgroundloader = new Thread(new ThreadStart(BackgroundLoad)); + backgroundloader = new Thread(BackgroundLoad); backgroundloader.Name = "Background Loader"; backgroundloader.Priority = ThreadPriority.Lowest; backgroundloader.IsBackground = true; diff --git a/Source/Core/Data/PreviewManager.cs b/Source/Core/Data/PreviewManager.cs index cc829561..63ba70cd 100644 --- a/Source/Core/Data/PreviewManager.cs +++ b/Source/Core/Data/PreviewManager.cs @@ -35,7 +35,7 @@ namespace CodeImp.DoomBuilder.Data private const PixelFormat IMAGE_FORMAT = PixelFormat.Format32bppArgb; // Dimensions of a single preview image - public static readonly int[] PREVIEW_SIZES = new int[] { 48, 64, 80, 96, 112, 128 }; + public static readonly int[] PREVIEW_SIZES = new[] { 48, 64, 80, 96, 112, 128 }; #endregion @@ -113,11 +113,8 @@ namespace CodeImp.DoomBuilder.Data // This makes a preview for the given image and updates the image settings private void MakeImagePreview(ImageData img) { - int previewwidth, previewheight; int imagewidth, imageheight; - Bitmap preview; - Graphics g; - + lock(img) { // Load image if needed @@ -129,28 +126,29 @@ namespace CodeImp.DoomBuilder.Data } else { - imagewidth = img.GetBitmap().Size.Width; - imageheight = img.GetBitmap().Size.Height; + Size size = img.GetBitmap().Size; //mxd + imagewidth = size.Width; + imageheight = size.Height; } // Determine preview size float scalex = (img.Width > maxpreviewwidth) ? (maxpreviewwidth / (float)imagewidth) : 1.0f; float scaley = (img.Height > maxpreviewheight) ? (maxpreviewheight / (float)imageheight) : 1.0f; float scale = Math.Min(scalex, scaley); - previewwidth = (int)(imagewidth * scale); - previewheight = (int)(imageheight * scale); + int previewwidth = (int)(imagewidth * scale); + int previewheight = (int)(imageheight * scale); if(previewwidth < 1) previewwidth = 1; if(previewheight < 1) previewheight = 1; // Make new image - preview = new Bitmap(previewwidth, previewheight, IMAGE_FORMAT); - g = Graphics.FromImage(preview); + Bitmap preview = new Bitmap(previewwidth, previewheight, IMAGE_FORMAT); + Graphics g = Graphics.FromImage(preview); g.PageUnit = GraphicsUnit.Pixel; - g.CompositingQuality = CompositingQuality.HighQuality; + //g.CompositingQuality = CompositingQuality.HighQuality; //mxd g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.SmoothingMode = SmoothingMode.HighQuality; + //g.SmoothingMode = SmoothingMode.HighQuality; //mxd g.PixelOffsetMode = PixelOffsetMode.None; - g.Clear(Color.Transparent); + //g.Clear(Color.Transparent); //mxd // Draw image onto atlas Rectangle atlasrect = new Rectangle(0, 0, previewwidth, previewheight); diff --git a/Source/Core/General/General.cs b/Source/Core/General/General.cs index a0f5882d..65347526 100644 --- a/Source/Core/General/General.cs +++ b/Source/Core/General/General.cs @@ -1848,14 +1848,14 @@ namespace CodeImp.DoomBuilder // This calculates the new rectangle when one is scaled into another keeping aspect ratio public static RectangleF MakeZoomedRect(Size source, RectangleF target) { - return MakeZoomedRect(new SizeF((int)source.Width, (int)source.Height), target); + return MakeZoomedRect(new SizeF(source.Width, source.Height), target); } // This calculates the new rectangle when one is scaled into another keeping aspect ratio public static RectangleF MakeZoomedRect(Size source, Rectangle target) { - return MakeZoomedRect(new SizeF((int)source.Width, (int)source.Height), - new RectangleF((int)target.Left, (int)target.Top, (int)target.Width, (int)target.Height)); + return MakeZoomedRect(new SizeF(source.Width, source.Height), + new RectangleF(target.Left, target.Top, target.Width, target.Height)); } // This calculates the new rectangle when one is scaled into another keeping aspect ratio diff --git a/Source/Plugins/BuilderEffects/BuilderEffects.csproj b/Source/Plugins/BuilderEffects/BuilderEffects.csproj index a81f01c3..4a64843b 100644 --- a/Source/Plugins/BuilderEffects/BuilderEffects.csproj +++ b/Source/Plugins/BuilderEffects/BuilderEffects.csproj @@ -88,6 +88,13 @@ MenusForm.cs + + Form + + + ObjImportSettingsForm.cs + + True @@ -113,6 +120,9 @@ JitterVerticesForm.cs + + ObjImportSettingsForm.cs + ResXFileCodeGenerator Resources.Designer.cs @@ -125,6 +135,9 @@ + + + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - text/microsoft-resx + text/microsoft-resx - 2.0 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 17, 17 + 17, 17 \ No newline at end of file diff --git a/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.Designer.cs b/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.Designer.cs new file mode 100644 index 00000000..00b0432c --- /dev/null +++ b/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.Designer.cs @@ -0,0 +1,230 @@ +namespace CodeImp.DoomBuilder.BuilderEffects +{ + partial class ObjImportSettingsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if(disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.label2 = new System.Windows.Forms.Label(); + this.nudScale = new System.Windows.Forms.NumericUpDown(); + this.cancel = new System.Windows.Forms.Button(); + this.import = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.browse = new System.Windows.Forms.Button(); + this.tbImportPath = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.axisx = new System.Windows.Forms.RadioButton(); + this.axisy = new System.Windows.Forms.RadioButton(); + this.axisz = new System.Windows.Forms.RadioButton(); + this.panel1 = new System.Windows.Forms.Panel(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + ((System.ComponentModel.ISupportInitialize)(this.nudScale)).BeginInit(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 40); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(37, 13); + this.label2.TabIndex = 16; + this.label2.Text = "Scale:"; + // + // nudScale + // + this.nudScale.DecimalPlaces = 4; + this.nudScale.Location = new System.Drawing.Point(55, 38); + this.nudScale.Maximum = new decimal(new int[] { + 2048, + 0, + 0, + 0}); + this.nudScale.Minimum = new decimal(new int[] { + 2048, + 0, + 0, + -2147483648}); + this.nudScale.Name = "nudScale"; + this.nudScale.Size = new System.Drawing.Size(94, 20); + this.nudScale.TabIndex = 15; + this.nudScale.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + // + // cancel + // + this.cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancel.Location = new System.Drawing.Point(279, 82); + this.cancel.Name = "cancel"; + this.cancel.Size = new System.Drawing.Size(75, 23); + this.cancel.TabIndex = 14; + this.cancel.Text = "Cancel"; + this.cancel.UseVisualStyleBackColor = true; + this.cancel.Click += new System.EventHandler(this.cancel_Click); + // + // import + // + this.import.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.import.Location = new System.Drawing.Point(360, 82); + this.import.Name = "import"; + this.import.Size = new System.Drawing.Size(75, 23); + this.import.TabIndex = 13; + this.import.Text = "Import"; + this.import.UseVisualStyleBackColor = true; + this.import.Click += new System.EventHandler(this.import_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(18, 14); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(32, 13); + this.label1.TabIndex = 12; + this.label1.Text = "Path:"; + // + // browse + // + this.browse.Location = new System.Drawing.Point(360, 10); + this.browse.Name = "browse"; + this.browse.Size = new System.Drawing.Size(75, 23); + this.browse.TabIndex = 11; + this.browse.Text = "Browse..."; + this.browse.UseVisualStyleBackColor = true; + this.browse.Click += new System.EventHandler(this.browse_Click); + // + // tbImportPath + // + this.tbImportPath.Location = new System.Drawing.Point(55, 12); + this.tbImportPath.Name = "tbImportPath"; + this.tbImportPath.Size = new System.Drawing.Size(299, 20); + this.tbImportPath.TabIndex = 10; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(183, 40); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(45, 13); + this.label3.TabIndex = 17; + this.label3.Text = "Up axis:"; + // + // axisx + // + this.axisx.AutoSize = true; + this.axisx.Location = new System.Drawing.Point(3, 3); + this.axisx.Name = "axisx"; + this.axisx.Size = new System.Drawing.Size(32, 17); + this.axisx.TabIndex = 18; + this.axisx.TabStop = true; + this.axisx.Text = "X"; + this.axisx.UseVisualStyleBackColor = true; + // + // axisy + // + this.axisy.AutoSize = true; + this.axisy.Location = new System.Drawing.Point(41, 3); + this.axisy.Name = "axisy"; + this.axisy.Size = new System.Drawing.Size(32, 17); + this.axisy.TabIndex = 19; + this.axisy.TabStop = true; + this.axisy.Text = "Y"; + this.axisy.UseVisualStyleBackColor = true; + // + // axisz + // + this.axisz.AutoSize = true; + this.axisz.Location = new System.Drawing.Point(79, 3); + this.axisz.Name = "axisz"; + this.axisz.Size = new System.Drawing.Size(32, 17); + this.axisz.TabIndex = 20; + this.axisz.TabStop = true; + this.axisz.Text = "Z"; + this.axisz.UseVisualStyleBackColor = true; + // + // panel1 + // + this.panel1.Controls.Add(this.axisx); + this.panel1.Controls.Add(this.axisz); + this.panel1.Controls.Add(this.axisy); + this.panel1.Location = new System.Drawing.Point(234, 36); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(133, 24); + this.panel1.TabIndex = 21; + // + // openFileDialog + // + this.openFileDialog.DefaultExt = "obj"; + this.openFileDialog.FileName = "openFileDialog1"; + this.openFileDialog.Filter = "Wavefront obj files|*.obj"; + this.openFileDialog.Title = "Choose .obj file to import:"; + // + // ObjImportSettingsForm + // + this.AcceptButton = this.import; + this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.CancelButton = this.cancel; + this.ClientSize = new System.Drawing.Size(447, 109); + this.Controls.Add(this.panel1); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.nudScale); + this.Controls.Add(this.cancel); + this.Controls.Add(this.import); + this.Controls.Add(this.label1); + this.Controls.Add(this.browse); + this.Controls.Add(this.tbImportPath); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "ObjImportSettingsForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.Text = "Import Wavefront .obj"; + ((System.ComponentModel.ISupportInitialize)(this.nudScale)).EndInit(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label2; + private System.Windows.Forms.NumericUpDown nudScale; + private System.Windows.Forms.Button cancel; + private System.Windows.Forms.Button import; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button browse; + private System.Windows.Forms.TextBox tbImportPath; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.RadioButton axisx; + private System.Windows.Forms.RadioButton axisy; + private System.Windows.Forms.RadioButton axisz; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.OpenFileDialog openFileDialog; + } +} \ No newline at end of file diff --git a/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.cs b/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.cs new file mode 100644 index 00000000..2f5e6fa6 --- /dev/null +++ b/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.cs @@ -0,0 +1,78 @@ +#region ================== Namespaces + +using System; +using System.IO; +using System.Windows.Forms; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderEffects +{ + public partial class ObjImportSettingsForm : Form + { + #region ================== Variables + + private ImportObjAsTerrainMode.UpAxis axis; + + #endregion + + #region ================== Properties + + internal string FilePath { get { return tbImportPath.Text.Trim(); } } + internal ImportObjAsTerrainMode.UpAxis UpAxis { get { return axis; } } + internal float ObjScale { get { return (float)nudScale.Value; } } + + //todo: floor/ceiling textures? height offsets? ceiling extra height? + + #endregion + + public ObjImportSettingsForm() { + InitializeComponent(); + + //restore settings + axis = (ImportObjAsTerrainMode.UpAxis)General.Settings.ReadPluginSetting("objexportupaxis", 0); + nudScale.Value = (decimal)General.Settings.ReadPluginSetting("objexportscale", 1.0f); + + switch(axis) { + case ImportObjAsTerrainMode.UpAxis.X: axisx.Checked = true; break; + case ImportObjAsTerrainMode.UpAxis.Y: axisy.Checked = true; break; + case ImportObjAsTerrainMode.UpAxis.Z: axisz.Checked = true; break; + default: axisy.Checked = true; break; + } + } + + #region ================== Events + + private void browse_Click(object sender, EventArgs e) { + if(openFileDialog.ShowDialog() == DialogResult.OK) { + tbImportPath.Text = openFileDialog.FileName; + } + } + + private void import_Click(object sender, EventArgs e) { + if(nudScale.Value == 0) { + MessageBox.Show("Scale should not be zero!"); + return; + } + if(!File.Exists(tbImportPath.Text)) { + MessageBox.Show("Selected path does not exist!"); + return; + } + + axis = (axisy.Checked ? ImportObjAsTerrainMode.UpAxis.Y : (axisz.Checked ? ImportObjAsTerrainMode.UpAxis.Z : ImportObjAsTerrainMode.UpAxis.X)); + + //save settings + General.Settings.WritePluginSetting("objexportupaxis", (int)axis); + General.Settings.WritePluginSetting("objexportscale", (float)nudScale.Value); + + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void cancel_Click(object sender, EventArgs e) { + this.Close(); + } + + #endregion + } +} diff --git a/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.resx b/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.resx new file mode 100644 index 00000000..80a002dc --- /dev/null +++ b/Source/Plugins/BuilderEffects/Interface/ObjImportSettingsForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Source/Plugins/BuilderEffects/Modes/ImportObjAsTerrainMode.cs b/Source/Plugins/BuilderEffects/Modes/ImportObjAsTerrainMode.cs new file mode 100644 index 00000000..5b793e12 --- /dev/null +++ b/Source/Plugins/BuilderEffects/Modes/ImportObjAsTerrainMode.cs @@ -0,0 +1,304 @@ +#region ================== Namespaces + +using System; +using System.Collections.Generic; +using CodeImp.DoomBuilder.Editing; +using System.Windows.Forms; +using CodeImp.DoomBuilder.Geometry; +using System.IO; +using System.Globalization; +using CodeImp.DoomBuilder.Windows; +using CodeImp.DoomBuilder.Map; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderEffects +{ + [EditMode(DisplayName = "Terrain Importer", + SwitchAction = "importobjasterrain", + Volatile = true, + UseByDefault = true, + AllowCopyPaste = false)] + public class ImportObjAsTerrainMode : ClassicMode + { + #region ================== Constants + + private readonly static char[] space = { ' ' }; + private const string slash = "/"; + + #endregion + + #region ================== Variables + + private struct Face + { + public readonly Vector3D V1; + public readonly Vector3D V2; + public readonly Vector3D V3; + + public Face(Vector3D v1, Vector3D v2, Vector3D v3) { + V1 = v1; + V2 = v2; + V3 = v3; + } + } + + private readonly ObjImportSettingsForm form; + + #endregion + + #region ================== Properties + + internal enum UpAxis + { + Y, + Z, + X + } + + #endregion + + #region ================== Constructor + + public ImportObjAsTerrainMode() { + form = new ObjImportSettingsForm(); + } + + #endregion + + #region ================== Methods + + public override void OnEngage() { + if(!General.Map.UDMF) { + General.Interface.DisplayStatus(StatusType.Warning, "Terrain importer works only in UDMF map format!"); + OnCancel(); + } + + base.OnEngage(); + General.Map.Map.ClearAllSelected(); + + //show interface + if(form.ShowDialog() == DialogResult.OK && File.Exists(form.FilePath)) { + OnAccept(); + } else { + OnCancel(); + } + } + + public override void OnAccept() { + Cursor.Current = Cursors.AppStarting; + General.Interface.DisplayStatus(StatusType.Busy, "Creating geometry..."); + + // Collections! Everyone loves them! + List verts = new List(12); + List faces = new List(4); + int minZ = int.MaxValue; + int maxZ = int.MinValue; + + // Read .obj, create and select sectors + if(!readGeometry(form.FilePath, form.ObjScale, form.UpAxis, verts, faces, ref minZ, ref maxZ) || !createGeometry(verts, faces, minZ, maxZ + (maxZ - minZ)/2)) { + // Fial! + Cursor.Current = Cursors.Default; + + // Return to base mode + General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name); + } + + // Update caches + General.Map.Map.Update(); + General.Map.IsChanged = true; + + // Done + Cursor.Current = Cursors.Default; + + // Switch to Edit Selection mode + General.Editing.ChangeMode("EditSelectionMode", true); + } + + public override void OnCancel() { + // Cancel base class + base.OnCancel(); + + // Return to base mode + General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name); + } + + #endregion + + #region ================== Geometry creation + + private bool createGeometry(List verts, List faces, int minZ, int maxZ) { + //make undo + General.Map.UndoRedo.CreateUndo("Import Terrain"); + + //prepare mapset + List newlines = new List(); + MapSet map = General.Map.Map; + map.BeginAddRemove(); + map.SetCapacity(map.Vertices.Count + verts.Count, map.Linedefs.Count + faces.Count * 3, map.Sidedefs.Count + faces.Count * 3, map.Sectors.Count + faces.Count, 0); + + //terrain has many faces... let's create them + Dictionary newverts = new Dictionary(); + foreach(Face face in faces){ + Sector s = map.CreateSector(); + s.Selected = true; + s.FloorHeight = minZ; + s.CeilHeight = maxZ; + s.Brightness = General.Settings.DefaultBrightness; //todo: allow user to change this + s.SetCeilTexture(General.Map.Config.SkyFlatName); + s.SetFloorTexture(General.Map.Options.DefaultFloorTexture); //todo: allow user to change this + + Linedef newline = getLine(newverts, s, face.V1, face.V2); + if(newline != null) newlines.Add(newline); + + newline = getLine(newverts, s, face.V2, face.V3); + if(newline != null) newlines.Add(newline); + + newline = getLine(newverts, s, face.V3, face.V1); + if(newline != null) newlines.Add(newline); + + s.UpdateCache(); + } + + //update new lines + foreach(Linedef l in newlines){ + l.ApplySidedFlags(); + } + + map.EndAddRemove(); + return true; + } + + private Linedef getLine(Dictionary verts, Sector sector, Vector3D v1, Vector3D v2) { + Linedef line = null; + + //get start and end verts + Vertex start = getVertex(verts, v1); + Vertex end = getVertex(verts, v2); + + //check if the line is already created + foreach(Linedef l in start.Linedefs){ + if(l.End == end || l.Start == end) { + line = l; + break; + } + } + + //create a new line? + if(line == null) { + line = General.Map.Map.CreateLinedef(start, end); + + //create front sidedef and attach sector to it + General.Map.Map.CreateSidedef(line, true, sector); + } else { + //create back sidedef and attach sector to it + General.Map.Map.CreateSidedef(line, false, sector); + } + + line.Selected = true; + return line; + } + + private Vertex getVertex(Dictionary verts, Vector3D pos) { + //already there? + if(verts.ContainsKey(pos)) return verts[pos]; + + //make a new one + Vertex v = General.Map.Map.CreateVertex(pos); + v.ZFloor = pos.z; + verts.Add(pos, v); + return v; + } + + #endregion + + #region ================== .obj import + + private static bool readGeometry(string path, float scale, UpAxis axis, List verts, List faces, ref int minZ, ref int maxZ) { + using(StreamReader reader = File.OpenText(path)) { + string line; + float x, y, z; + int px, py, pz; + int counter = 0; + + while((line = reader.ReadLine()) != null) { + counter++; + + if(line.StartsWith("v ")) { + string[] parts = line.Split(space); + + if(parts.Length != 4 || !float.TryParse(parts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out x) || + !float.TryParse(parts[2], NumberStyles.Float, CultureInfo.InvariantCulture, out y) || + !float.TryParse(parts[3], NumberStyles.Float, CultureInfo.InvariantCulture, out z)) { + MessageBox.Show("Failed to parse vertex definition at line " + counter + "!", "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + //apply up axis + switch (axis) { + case UpAxis.Y: + px = (int)Math.Round(x * scale); + py = (int)Math.Round(-z * scale); + pz = (int)Math.Round(y * scale); + break; + + case UpAxis.Z: + px = (int)Math.Round(x * scale); + py = (int)Math.Round(-y * scale); + pz = (int)Math.Round(z * scale); + break; + + case UpAxis.X: + px = (int)Math.Round(y * scale); + py = (int)Math.Round(-z * scale); + pz = (int)Math.Round(x * scale); + break; + + default: //same as UpAxis.Y + px = (int)Math.Round(x * scale); + py = (int)Math.Round(-z * scale); + pz = (int)Math.Round(y * scale); + break; + } + + if(maxZ < pz) maxZ = pz; + if(minZ > pz) minZ = pz; + + verts.Add(new Vector3D(px, py, pz)); + + } else if(line.StartsWith("f ")) { + string[] parts = line.Split(space); + + if(parts.Length != 4) { + MessageBox.Show("Failed to parse face definition at line " + counter + ": only triangle faces are supported!", "Terrain Importer", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + //.obj vertex indices are 1-based + int v1 = readVertexIndex(parts[1]) - 1; + int v2 = readVertexIndex(parts[2]) - 1; + int v3 = readVertexIndex(parts[3]) - 1; + + if(verts[v1] == verts[v2] || verts[v1] == verts[v3] || verts[v2] == verts[v3]) continue; + + if (axis == UpAxis.X) { + faces.Add(new Face(verts[v1], verts[v2], verts[v3])); + } else { + faces.Add(new Face(verts[v3], verts[v2], verts[v1])); + } + } + } + } + + return true; + } + + private static int readVertexIndex(string def) { + int slashpos = def.IndexOf(slash); + if(slashpos != -1) def = def.Substring(0, slashpos); + return int.Parse(def); + } + + #endregion + } +} diff --git a/Source/Plugins/BuilderEffects/Properties/Resources.Designer.cs b/Source/Plugins/BuilderEffects/Properties/Resources.Designer.cs index d0435b86..c987373e 100644 --- a/Source/Plugins/BuilderEffects/Properties/Resources.Designer.cs +++ b/Source/Plugins/BuilderEffects/Properties/Resources.Designer.cs @@ -67,6 +67,13 @@ namespace CodeImp.DoomBuilder.BuilderEffects.Properties { } } + internal static System.Drawing.Bitmap Terrain { + get { + object obj = ResourceManager.GetObject("Terrain", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + internal static System.Drawing.Bitmap Update { get { object obj = ResourceManager.GetObject("Update", resourceCulture); diff --git a/Source/Plugins/BuilderEffects/Properties/Resources.resx b/Source/Plugins/BuilderEffects/Properties/Resources.resx index 513b950f..54c9ead1 100644 --- a/Source/Plugins/BuilderEffects/Properties/Resources.resx +++ b/Source/Plugins/BuilderEffects/Properties/Resources.resx @@ -1,127 +1,130 @@  + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - text/microsoft-resx + text/microsoft-resx - 2.0 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Resources\Update.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\Jitter.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\Jitter.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Update.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Terrain.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/Source/Plugins/BuilderEffects/Resources/Actions.cfg b/Source/Plugins/BuilderEffects/Resources/Actions.cfg index e34a084a..e11752ab 100644 --- a/Source/Plugins/BuilderEffects/Resources/Actions.cfg +++ b/Source/Plugins/BuilderEffects/Resources/Actions.cfg @@ -13,4 +13,14 @@ applyjitter allowmouse = false; allowscroll = false; default = 131146; //Ctrl-J +} + +importobjasterrain +{ + title = "Import Wavefront .obj as terrain"; + category = "transform"; + description = "Creates sectors using given model (UDMF only)"; + allowkeys = true; + allowmouse = false; + allowscroll = false; } \ No newline at end of file diff --git a/Source/Plugins/BuilderEffects/Resources/Terrain.png b/Source/Plugins/BuilderEffects/Resources/Terrain.png new file mode 100644 index 00000000..f4fdc5e3 Binary files /dev/null and b/Source/Plugins/BuilderEffects/Resources/Terrain.png differ diff --git a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs index 5d388aa0..21edabda 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs @@ -156,6 +156,13 @@ namespace CodeImp.DoomBuilder.BuilderModes mode = ModifyMode.None; } + //mxd. Another constructor + public EditSelectionMode(bool pasting) { + // Initialize + this.pasting = pasting; + this.mode = ModifyMode.None; + } + // Disposer public override void Dispose() { diff --git a/Source/Plugins/BuilderModes/General/BuilderPlug.cs b/Source/Plugins/BuilderModes/General/BuilderPlug.cs index ab12dda0..223c004e 100644 --- a/Source/Plugins/BuilderModes/General/BuilderPlug.cs +++ b/Source/Plugins/BuilderModes/General/BuilderPlug.cs @@ -118,9 +118,6 @@ namespace CodeImp.DoomBuilder.BuilderModes private bool autoDrawOnEdit; //mxd private bool marqueSelectTouching; //mxd. Select elements partially/fully inside of marque selection? private bool syncSelection; //mxd. Sync selection between Visual and Classic modes. - private bool objExportTextures; //mxd - private bool objGZDoomScale; //mxd - private float objScale; //mxd private bool lockSectorTextureOffsetsWhileDragging; //mxd #endregion @@ -181,9 +178,6 @@ namespace CodeImp.DoomBuilder.BuilderModes public bool DontMoveGeometryOutsideMapBoundary { get { return dontMoveGeometryOutsideMapBoundary; } set { DontMoveGeometryOutsideMapBoundary = value; } } //mxd public bool MarqueSelectTouching { get { return marqueSelectTouching; } set { marqueSelectTouching = value; } } //mxd public bool SyncSelection { get { return syncSelection; } set { syncSelection = value; } } //mxd - public bool ObjExportTextures { get { return objExportTextures; } internal set { objExportTextures = value; } } //mxd - public bool ObjGZDoomScale { get { return objGZDoomScale; } internal set { objGZDoomScale = value; } } //mxd - public float ObjScale { get { return objScale; } internal set { objScale = value; } } //mxd public bool LockSectorTextureOffsetsWhileDragging { get { return lockSectorTextureOffsetsWhileDragging; } internal set { lockSectorTextureOffsetsWhileDragging = value; } } //mxd #endregion @@ -224,14 +218,14 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. Export to .obj exportToObjMenuItem = new ToolStripMenuItem("Export to .obj..."); exportToObjMenuItem.Tag = "exporttoobj"; - exportToObjMenuItem.Click += new EventHandler(InvokeTaggedAction); + exportToObjMenuItem.Click += InvokeTaggedAction; exportToObjMenuItem.Enabled = false; General.Interface.AddMenu(exportToObjMenuItem, MenuSection.FileNewOpenClose); //mxd. add "Snap Vertices" menu button snapModeMenuItem = new ToolStripMenuItem("Snap selected map elements to grid"); snapModeMenuItem.Tag = "snapvertstogrid"; - snapModeMenuItem.Click += new EventHandler(InvokeTaggedAction); + snapModeMenuItem.Click += InvokeTaggedAction; snapModeMenuItem.Image = Properties.Resources.SnapVerts; snapModeMenuItem.Enabled = false; General.Interface.AddMenu(snapModeMenuItem, MenuSection.EditGeometry); @@ -240,7 +234,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //draw ellipse drawEllipseModeMenuItem = new ToolStripMenuItem("Draw Ellipse"); drawEllipseModeMenuItem.Tag = "drawellipsemode"; - drawEllipseModeMenuItem.Click += new EventHandler(InvokeTaggedAction); + drawEllipseModeMenuItem.Click += InvokeTaggedAction; drawEllipseModeMenuItem.Image = Properties.Resources.DrawEllipseMode; drawEllipseModeMenuItem.Enabled = false; General.Interface.AddMenu(drawEllipseModeMenuItem, MenuSection.ModeDrawModes); @@ -248,7 +242,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //draw grid drawGridModeMenuItem = new ToolStripMenuItem("Draw Grid"); drawGridModeMenuItem.Tag = "drawgridmode"; - drawGridModeMenuItem.Click += new EventHandler(InvokeTaggedAction); + drawGridModeMenuItem.Click += InvokeTaggedAction; drawGridModeMenuItem.Image = Properties.Resources.DrawGridMode; drawGridModeMenuItem.Enabled = false; General.Interface.AddMenu(drawGridModeMenuItem, MenuSection.ModeDrawModes); @@ -256,7 +250,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //draw rectangle drawRectModeMenuItem = new ToolStripMenuItem("Draw Rectangle"); drawRectModeMenuItem.Tag = "drawrectanglemode"; - drawRectModeMenuItem.Click += new EventHandler(InvokeTaggedAction); + drawRectModeMenuItem.Click += InvokeTaggedAction; drawRectModeMenuItem.Image = Properties.Resources.DrawRectMode; drawRectModeMenuItem.Enabled = false; General.Interface.AddMenu(drawRectModeMenuItem, MenuSection.ModeDrawModes); @@ -264,7 +258,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //draw curve drawCurveModeMenuItem = new ToolStripMenuItem("Draw Curve"); drawCurveModeMenuItem.Tag = "drawcurvemode"; - drawCurveModeMenuItem.Click += new EventHandler(InvokeTaggedAction); + drawCurveModeMenuItem.Click += InvokeTaggedAction; drawCurveModeMenuItem.Image = Properties.Resources.DrawCurveMode; drawCurveModeMenuItem.Enabled = false; General.Interface.AddMenu(drawCurveModeMenuItem, MenuSection.ModeDrawModes); @@ -272,7 +266,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //draw lines drawLinesModeMenuItem = new ToolStripMenuItem("Draw Lines"); drawLinesModeMenuItem.Tag = "drawlinesmode"; - drawLinesModeMenuItem.Click += new EventHandler(InvokeTaggedAction); + drawLinesModeMenuItem.Click += InvokeTaggedAction; drawLinesModeMenuItem.Image = Properties.Resources.DrawLinesMode; drawLinesModeMenuItem.Enabled = false; General.Interface.AddMenu(drawLinesModeMenuItem, MenuSection.ModeDrawModes); @@ -341,9 +335,6 @@ namespace CodeImp.DoomBuilder.BuilderModes autoAlignTextureOffsetsOnCreate = General.Settings.ReadPluginSetting("autoaligntextureoffsetsoncreate", false); //mxd dontMoveGeometryOutsideMapBoundary = General.Settings.ReadPluginSetting("dontmovegeometryoutsidemapboundary", false); //mxd syncSelection = General.Settings.ReadPluginSetting("syncselection", false); //mxd - objExportTextures = General.Settings.ReadPluginSetting("objexporttextures", false); //mxd - objGZDoomScale = General.Settings.ReadPluginSetting("objgzdoomscale", false); //mxd - objScale = General.Settings.ReadPluginSetting("objscale", 1.0f); //mxd lockSectorTextureOffsetsWhileDragging = General.Settings.ReadPluginSetting("locktextureoffsets", false); //mxd } @@ -922,7 +913,7 @@ namespace CodeImp.DoomBuilder.BuilderModes //show settings form WavefrontSettingsForm form = new WavefrontSettingsForm(General.Map.Map.SelectedSectorsCount == 0 ? -1 : sectors.Count); if(form.ShowDialog() == DialogResult.OK) { - WavefrontExportSettings data = new WavefrontExportSettings(Path.GetFileNameWithoutExtension(form.FilePath), Path.GetDirectoryName(form.FilePath), BuilderPlug.Me.ObjScale, BuilderPlug.Me.ObjGZDoomScale, BuilderPlug.Me.ObjExportTextures); + WavefrontExportSettings data = new WavefrontExportSettings(Path.GetFileNameWithoutExtension(form.FilePath), Path.GetDirectoryName(form.FilePath), form.ObjScale, form.UseGZDoomScale, form.ExportTextures); WavefrontExporter e = new WavefrontExporter(); e.Export(sectors, data); } diff --git a/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.Designer.cs b/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.Designer.cs index 09e1e8f8..cc378b53 100644 --- a/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.Designer.cs +++ b/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.Designer.cs @@ -27,6 +27,8 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.ceiling = new CodeImp.DoomBuilder.Controls.FlatSelectorControl(); + this.floor = new CodeImp.DoomBuilder.Controls.FlatSelectorControl(); this.cbOverrideFloorTexture = new System.Windows.Forms.CheckBox(); this.cbOverrideCeilingTexture = new System.Windows.Forms.CheckBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); @@ -58,8 +60,8 @@ this.clearfloor = new System.Windows.Forms.Button(); this.clearceiling = new System.Windows.Forms.Button(); this.groupBox5 = new System.Windows.Forms.GroupBox(); - this.floor = new CodeImp.DoomBuilder.Controls.FlatSelectorControl(); - this.ceiling = new CodeImp.DoomBuilder.Controls.FlatSelectorControl(); + this.fillall = new System.Windows.Forms.Button(); + this.clearall = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -82,6 +84,24 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Sector texture overrides:"; // + // ceiling + // + this.ceiling.Location = new System.Drawing.Point(6, 41); + this.ceiling.Name = "ceiling"; + this.ceiling.Size = new System.Drawing.Size(68, 90); + this.ceiling.TabIndex = 30; + this.ceiling.TextureName = ""; + this.ceiling.OnValueChanged += new System.EventHandler(this.ceiling_OnValueChanged); + // + // floor + // + this.floor.Location = new System.Drawing.Point(87, 41); + this.floor.Name = "floor"; + this.floor.Size = new System.Drawing.Size(68, 90); + this.floor.TabIndex = 29; + this.floor.TextureName = ""; + this.floor.OnValueChanged += new System.EventHandler(this.floor_OnValueChanged); + // // cbOverrideFloorTexture // this.cbOverrideFloorTexture.AutoSize = true; @@ -300,6 +320,7 @@ // this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox4.Controls.Add(this.fillall); this.groupBox4.Controls.Add(this.filllower); this.groupBox4.Controls.Add(this.fillmiddle); this.groupBox4.Controls.Add(this.fillupper); @@ -314,7 +335,7 @@ // // filllower // - this.filllower.Location = new System.Drawing.Point(133, 19); + this.filllower.Location = new System.Drawing.Point(171, 19); this.filllower.Name = "filllower"; this.filllower.Size = new System.Drawing.Size(26, 23); this.filllower.TabIndex = 4; @@ -325,7 +346,7 @@ // // fillmiddle // - this.fillmiddle.Location = new System.Drawing.Point(101, 19); + this.fillmiddle.Location = new System.Drawing.Point(139, 19); this.fillmiddle.Name = "fillmiddle"; this.fillmiddle.Size = new System.Drawing.Size(26, 23); this.fillmiddle.TabIndex = 3; @@ -336,7 +357,7 @@ // // fillupper // - this.fillupper.Location = new System.Drawing.Point(69, 19); + this.fillupper.Location = new System.Drawing.Point(107, 19); this.fillupper.Name = "fillupper"; this.fillupper.Size = new System.Drawing.Size(26, 23); this.fillupper.TabIndex = 2; @@ -347,7 +368,7 @@ // // fillfloor // - this.fillfloor.Location = new System.Drawing.Point(38, 19); + this.fillfloor.Location = new System.Drawing.Point(76, 19); this.fillfloor.Name = "fillfloor"; this.fillfloor.Size = new System.Drawing.Size(26, 23); this.fillfloor.TabIndex = 1; @@ -358,7 +379,7 @@ // // fillceiling // - this.fillceiling.Location = new System.Drawing.Point(6, 19); + this.fillceiling.Location = new System.Drawing.Point(44, 19); this.fillceiling.Name = "fillceiling"; this.fillceiling.Size = new System.Drawing.Size(26, 23); this.fillceiling.TabIndex = 0; @@ -370,7 +391,7 @@ // // clearlower // - this.clearlower.Location = new System.Drawing.Point(133, 19); + this.clearlower.Location = new System.Drawing.Point(171, 19); this.clearlower.Name = "clearlower"; this.clearlower.Size = new System.Drawing.Size(26, 23); this.clearlower.TabIndex = 4; @@ -381,7 +402,7 @@ // // clearmiddle // - this.clearmiddle.Location = new System.Drawing.Point(101, 19); + this.clearmiddle.Location = new System.Drawing.Point(139, 19); this.clearmiddle.Name = "clearmiddle"; this.clearmiddle.Size = new System.Drawing.Size(26, 23); this.clearmiddle.TabIndex = 3; @@ -392,7 +413,7 @@ // // clearupper // - this.clearupper.Location = new System.Drawing.Point(69, 19); + this.clearupper.Location = new System.Drawing.Point(107, 19); this.clearupper.Name = "clearupper"; this.clearupper.Size = new System.Drawing.Size(26, 23); this.clearupper.TabIndex = 2; @@ -403,7 +424,7 @@ // // clearfloor // - this.clearfloor.Location = new System.Drawing.Point(38, 19); + this.clearfloor.Location = new System.Drawing.Point(76, 19); this.clearfloor.Name = "clearfloor"; this.clearfloor.Size = new System.Drawing.Size(26, 23); this.clearfloor.TabIndex = 1; @@ -414,7 +435,7 @@ // // clearceiling // - this.clearceiling.Location = new System.Drawing.Point(6, 19); + this.clearceiling.Location = new System.Drawing.Point(44, 19); this.clearceiling.Name = "clearceiling"; this.clearceiling.Size = new System.Drawing.Size(26, 23); this.clearceiling.TabIndex = 0; @@ -427,6 +448,7 @@ // this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox5.Controls.Add(this.clearall); this.groupBox5.Controls.Add(this.clearlower); this.groupBox5.Controls.Add(this.clearmiddle); this.groupBox5.Controls.Add(this.clearupper); @@ -439,23 +461,27 @@ this.groupBox5.TabStop = false; this.groupBox5.Text = "Remove Textures form Selection:"; // - // floor + // fillall // - this.floor.Location = new System.Drawing.Point(87, 41); - this.floor.Name = "floor"; - this.floor.Size = new System.Drawing.Size(68, 90); - this.floor.TabIndex = 29; - this.floor.TextureName = ""; - this.floor.OnValueChanged += new System.EventHandler(this.floor_OnValueChanged); + this.fillall.Location = new System.Drawing.Point(6, 19); + this.fillall.Name = "fillall"; + this.fillall.Size = new System.Drawing.Size(32, 23); + this.fillall.TabIndex = 5; + this.fillall.Text = "All"; + this.toolTip1.SetToolTip(this.fillall, "Replace all textures with currently enabled overrides"); + this.fillall.UseVisualStyleBackColor = true; + this.fillall.Click += new System.EventHandler(this.fillall_Click); // - // ceiling + // clearall // - this.ceiling.Location = new System.Drawing.Point(6, 41); - this.ceiling.Name = "ceiling"; - this.ceiling.Size = new System.Drawing.Size(68, 90); - this.ceiling.TabIndex = 30; - this.ceiling.TextureName = ""; - this.ceiling.OnValueChanged += new System.EventHandler(this.ceiling_OnValueChanged); + this.clearall.Location = new System.Drawing.Point(6, 19); + this.clearall.Name = "clearall"; + this.clearall.Size = new System.Drawing.Size(32, 23); + this.clearall.TabIndex = 6; + this.clearall.Text = "All"; + this.toolTip1.SetToolTip(this.clearall, "Remove all textures from selected map elements"); + this.clearall.UseVisualStyleBackColor = true; + this.clearall.Click += new System.EventHandler(this.clearall_Click); // // SectorDrawingOptionsPanel // @@ -516,5 +542,7 @@ private System.Windows.Forms.Button clearceiling; private CodeImp.DoomBuilder.Controls.FlatSelectorControl floor; private CodeImp.DoomBuilder.Controls.FlatSelectorControl ceiling; + private System.Windows.Forms.Button fillall; + private System.Windows.Forms.Button clearall; } } diff --git a/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.cs b/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.cs index 7bbda42c..3c6f605f 100644 --- a/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.cs +++ b/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.cs @@ -147,7 +147,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface General.Map.Data.UpdateUsedTextures(); General.Map.IsChanged = true; - if(General.Map.Renderer2D.ViewMode == CodeImp.DoomBuilder.Rendering.ViewMode.CeilingTextures) + if(General.Map.Renderer2D.ViewMode == Rendering.ViewMode.CeilingTextures) General.Interface.RedrawDisplay(); } @@ -167,7 +167,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface General.Map.Data.UpdateUsedTextures(); General.Map.IsChanged = true; - if(General.Map.Renderer2D.ViewMode == CodeImp.DoomBuilder.Rendering.ViewMode.FloorTextures) + if(General.Map.Renderer2D.ViewMode == Rendering.ViewMode.FloorTextures) General.Interface.RedrawDisplay(); } @@ -225,6 +225,59 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface General.Map.IsChanged = true; } + private void fillall_Click(object sender, EventArgs e) { + ICollection sectors = General.Map.Map.GetSelectedSectors(true); + + //if we have selected sectors - fill their textures + if (sectors.Count > 0) { + //make undo + General.Map.UndoRedo.CreateUndo("Fill all texturs for " + sectors.Count + (sectors.Count > 1 ? " sectors" : " sector")); + + foreach (Sector s in sectors) { + //fill sidedefs + foreach(Sidedef side in s.Sidedefs) { + if(top.Enabled && side.HighRequired()) side.SetTextureHigh(top.TextureName); + if(middle.Enabled && side.MiddleRequired()) side.SetTextureMid(middle.TextureName); + if(bottom.Enabled && side.LowRequired()) side.SetTextureLow(bottom.TextureName); + } + + //fill flats + if(floor.Enabled) s.SetFloorTexture(floor.TextureName); + if(ceiling.Enabled) s.SetCeilTexture(ceiling.TextureName); + } + } else { //if we don't - fill linedef textures + ICollection lines = General.Map.Map.GetSelectedLinedefs(true); + if(lines.Count == 0) return; + + //make undo + General.Map.UndoRedo.CreateUndo("Fill all texturs for " + lines.Count + (lines.Count > 1 ? " linedefs" : " linedef")); + + //fill textures + foreach (Linedef l in lines) { + if(top.Enabled) { + if(l.Front != null && l.Front.HighRequired()) l.Front.SetTextureHigh(top.TextureName); + if(l.Back != null && l.Back.HighRequired()) l.Back.SetTextureHigh(top.TextureName); + } + if(middle.Enabled) { + if(l.Front != null && l.Front.MiddleRequired()) l.Front.SetTextureMid(middle.TextureName); + if(l.Back != null && l.Back.MiddleRequired()) l.Back.SetTextureMid(middle.TextureName); + } + if(bottom.Enabled) { + if(l.Front != null && l.Front.LowRequired()) l.Front.SetTextureLow(bottom.TextureName); + if(l.Back != null && l.Back.LowRequired()) l.Back.SetTextureLow(bottom.TextureName); + } + } + } + + // Update the used textures + General.Map.Data.UpdateUsedTextures(); + General.Map.IsChanged = true; + + // Update entire display + General.Map.Map.Update(); + General.Interface.RedrawDisplay(); + } + #endregion #region Clear Textures @@ -247,7 +300,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface // Update entire display General.Map.Map.Update(); - if(General.Map.Renderer2D.ViewMode == CodeImp.DoomBuilder.Rendering.ViewMode.CeilingTextures) + if(General.Map.Renderer2D.ViewMode == Rendering.ViewMode.CeilingTextures) General.Interface.RedrawDisplay(); } @@ -269,7 +322,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface // Update entire display General.Map.Map.Update(); - if(General.Map.Renderer2D.ViewMode == CodeImp.DoomBuilder.Rendering.ViewMode.FloorTextures) + if(General.Map.Renderer2D.ViewMode == Rendering.ViewMode.FloorTextures) General.Interface.RedrawDisplay(); } @@ -327,6 +380,61 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface General.Map.IsChanged = true; } + private void clearall_Click(object sender, EventArgs e) { + //if we have selected sectors - clear their textures + ICollection sectors = General.Map.Map.GetSelectedSectors(true); + if (sectors.Count > 0) { + //make undo + string undodesc = "sector"; + if(sectors.Count > 1) undodesc = sectors.Count + " sectors"; + General.Map.UndoRedo.CreateUndo("Clear all texture from " + undodesc); + + foreach(Sector s in sectors) { + //clear side textures + foreach (Sidedef side in s.Sidedefs) { + if(side.HighTexture != "-") side.SetTextureHigh("-"); + if(side.MiddleTexture != "-") side.SetTextureMid("-"); + if(side.LowTexture != "-") side.SetTextureLow("-"); + } + + //clear flats + s.SetCeilTexture("-"); + s.SetFloorTexture("-"); + } + + } else { //if we don't - clear linedef textures + ICollection lines = General.Map.Map.GetSelectedLinedefs(true); + if(lines.Count == 0) return; + + //make undo + string undodesc = "linedef"; + if(lines.Count > 1) undodesc = lines.Count + " linedefs"; + General.Map.UndoRedo.CreateUndo("Clear all texture from " + undodesc); + + //clear textures + foreach(Linedef l in lines) { + if(l.Front != null) { + if(l.Front.HighTexture != "-") l.Front.SetTextureHigh("-"); + if(l.Front.MiddleTexture != "-") l.Front.SetTextureMid("-"); + if(l.Front.LowTexture != "-") l.Front.SetTextureLow("-"); + } + if (l.Back != null) { + if(l.Back.HighTexture != "-") l.Back.SetTextureHigh("-"); + if(l.Back.MiddleTexture != "-") l.Back.SetTextureMid("-"); + if(l.Back.LowTexture != "-") l.Back.SetTextureLow("-"); + } + } + } + + // Update the used textures + General.Map.Data.UpdateUsedTextures(); + General.Map.IsChanged = true; + + // Update entire display + General.Map.Map.Update(); + General.Interface.RedrawDisplay(); + } + #endregion } diff --git a/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.resx b/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.resx index 7ce03af8..e641aef8 100644 --- a/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.resx +++ b/Source/Plugins/BuilderModes/Interface/SectorDrawingOptionsPanel.resx @@ -120,4 +120,7 @@ 17, 17 + + 17, 17 + \ No newline at end of file diff --git a/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.Designer.cs b/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.Designer.cs index 58f86dde..70ce04e5 100644 --- a/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.Designer.cs +++ b/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.Designer.cs @@ -40,9 +40,9 @@ // // tbExportPath // - this.tbExportPath.Location = new System.Drawing.Point(82, 12); + this.tbExportPath.Location = new System.Drawing.Point(55, 12); this.tbExportPath.Name = "tbExportPath"; - this.tbExportPath.Size = new System.Drawing.Size(272, 20); + this.tbExportPath.Size = new System.Drawing.Size(299, 20); this.tbExportPath.TabIndex = 0; // // browse @@ -58,11 +58,11 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 15); + this.label1.Location = new System.Drawing.Point(18, 14); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(65, 14); + this.label1.Size = new System.Drawing.Size(31, 14); this.label1.TabIndex = 2; - this.label1.Text = "Export path:"; + this.label1.Text = "Path:"; // // cbFixScale // @@ -116,30 +116,30 @@ // nudScale // this.nudScale.DecimalPlaces = 4; - this.nudScale.Location = new System.Drawing.Point(82, 38); + this.nudScale.Location = new System.Drawing.Point(55, 38); this.nudScale.Maximum = new decimal(new int[] { - 2048, - 0, - 0, - 0}); + 2048, + 0, + 0, + 0}); this.nudScale.Minimum = new decimal(new int[] { - 2048, - 0, - 0, - -2147483648}); + 2048, + 0, + 0, + -2147483648}); this.nudScale.Name = "nudScale"; this.nudScale.Size = new System.Drawing.Size(94, 20); this.nudScale.TabIndex = 8; this.nudScale.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); + 1, + 0, + 0, + 0}); // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(39, 40); + this.label2.Location = new System.Drawing.Point(12, 40); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(37, 14); this.label2.TabIndex = 9; diff --git a/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.cs b/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.cs index c76acc71..f40372c5 100644 --- a/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.cs +++ b/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.cs @@ -1,27 +1,46 @@ -using System; +#region ================== Namespaces + +using System; using System.Windows.Forms; using System.IO; +#endregion + namespace CodeImp.DoomBuilder.BuilderModes.Interface { public partial class WavefrontSettingsForm : Form { - public string FilePath { get { return filePath; } } - private string filePath; - + #region ================== Properties + + public string FilePath { get { return tbExportPath.Text.Trim(); } } + public bool ExportTextures { get { return cbExportTextures.Checked; } } + public bool UseGZDoomScale { get { return cbFixScale.Checked; } } + public float ObjScale { get { return (float)nudScale.Value; } } + + #endregion + public WavefrontSettingsForm(int sectorsCount) { InitializeComponent(); - saveFileDialog.InitialDirectory = General.Map.FilePathName; - saveFileDialog.FileName = Path.GetDirectoryName(General.Map.FilePathName) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(General.Map.FileTitle) + "_" + General.Map.Options.LevelName + ".obj"; - tbExportPath.Text = saveFileDialog.FileName; - cbExportTextures.Checked = BuilderPlug.Me.ObjExportTextures; - cbFixScale.Checked = BuilderPlug.Me.ObjGZDoomScale; - nudScale.Value = (decimal)BuilderPlug.Me.ObjScale; + string name = Path.GetFileNameWithoutExtension(General.Map.FileTitle) + "_" + General.Map.Options.LevelName + ".obj"; + if(string.IsNullOrEmpty(General.Map.FilePathName)) { + saveFileDialog.FileName = name; + } else { + saveFileDialog.InitialDirectory = General.Map.FilePathName; + saveFileDialog.FileName = Path.GetDirectoryName(General.Map.FilePathName) + Path.DirectorySeparatorChar + name; + tbExportPath.Text = saveFileDialog.FileName; + } + + //restore settings + cbExportTextures.Checked = General.Settings.ReadPluginSetting("objexporttextures", false);//BuilderPlug.Me.ObjExportTextures; + cbFixScale.Checked = General.Settings.ReadPluginSetting("objgzdoomscale", false);//BuilderPlug.Me.ObjGZDoomScale; + nudScale.Value = (decimal)General.Settings.ReadPluginSetting("objscale", 1.0f);//(decimal)BuilderPlug.Me.ObjScale; this.Text = "Export " + (sectorsCount == -1 ? "whole map" : sectorsCount + (sectorsCount > 1 ? "sectors" : "sector")) + " to Wavefront .obj"; } + #region ================== Events + private void browse_Click(object sender, EventArgs e) { if(saveFileDialog.ShowDialog() == DialogResult.OK) { tbExportPath.Text = saveFileDialog.FileName; @@ -29,29 +48,34 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface } private void export_Click(object sender, EventArgs e) { - filePath = tbExportPath.Text.Trim(); + //BuilderPlug.Me.ObjExportTextures = cbExportTextures.Checked; + //BuilderPlug.Me.ObjGZDoomScale = cbFixScale.Checked; + //BuilderPlug.Me.ObjScale = (float)nudScale.Value; - BuilderPlug.Me.ObjExportTextures = cbExportTextures.Checked; - BuilderPlug.Me.ObjGZDoomScale = cbFixScale.Checked; - BuilderPlug.Me.ObjScale = (float)nudScale.Value; + if(nudScale.Value == 0) { + MessageBox.Show("Scale should not be zero!"); + return; + } + if(!Directory.Exists(Path.GetDirectoryName(tbExportPath.Text))) { + MessageBox.Show("Selected path does not exist!"); + return; + } //save settings - General.Settings.WritePluginSetting("objexporttextures", cbExportTextures.Checked);//mxd - General.Settings.WritePluginSetting("objgzdoomscale", cbFixScale.Checked);//mxd - General.Settings.WritePluginSetting("objscale", (float)nudScale.Value);//mxd - - //verify path - if(Directory.Exists(Path.GetDirectoryName(filePath))) { - filePath = tbExportPath.Text; - this.DialogResult = DialogResult.OK; - this.Close(); - } else { - MessageBox.Show("Selected path does not exist!"); - } + General.Settings.WritePluginSetting("objexporttextures", cbExportTextures.Checked); + General.Settings.WritePluginSetting("objgzdoomscale", cbFixScale.Checked); + General.Settings.WritePluginSetting("objscale", (float)nudScale.Value); + + //filePath = tbExportPath.Text; + this.DialogResult = DialogResult.OK; + this.Close(); } private void cancel_Click(object sender, EventArgs e) { this.Close(); } + + #endregion + } } diff --git a/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.resx b/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.resx index c87dfbaa..4d4fe7b6 100644 --- a/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.resx +++ b/Source/Plugins/BuilderModes/Interface/WavefrontSettingsForm.resx @@ -1,123 +1,123 @@ + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - text/microsoft-resx + text/microsoft-resx - 2.0 + 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 17, 17 + 17, 17 \ No newline at end of file