From 05319ab7fe554cdb1802a048268cc745ad36680b Mon Sep 17 00:00:00 2001 From: Xabis Date: Fri, 18 Dec 2020 21:39:46 -0500 Subject: [PATCH] Added spline support to speed adjustment utility --- PathTools.csproj | 9 ++- fTools.Designer.cs | 160 +++++++++++++++++++++------------------------ fTools.cs | 94 ++++++++++++++++++++------ fTools.resx | 4 +- 4 files changed, 159 insertions(+), 108 deletions(-) diff --git a/PathTools.csproj b/PathTools.csproj index d3c8ff8..b22e50f 100644 --- a/PathTools.csproj +++ b/PathTools.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,7 +10,7 @@ Properties TriDelta.PathTools PathTools - v3.5 + v4.7.2 512 @@ -31,6 +31,7 @@ false false true + true @@ -41,6 +42,7 @@ prompt 4 AllRules.ruleset + false pdbonly @@ -51,6 +53,7 @@ 4 AnyCPU AllRules.ruleset + false true @@ -60,6 +63,7 @@ x86 prompt AllRules.ruleset + false ..\..\..\Build\Plugins\ @@ -69,6 +73,7 @@ x86 prompt AllRules.ruleset + false diff --git a/fTools.Designer.cs b/fTools.Designer.cs index 9a3df33..0728e0c 100644 --- a/fTools.Designer.cs +++ b/fTools.Designer.cs @@ -41,6 +41,8 @@ private void InitializeComponent() this.label12 = new System.Windows.Forms.Label(); this.txtRetagStart = new System.Windows.Forms.TextBox(); this.grpCreateThings = new System.Windows.Forms.GroupBox(); + this.label14 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); this.txtHOffset = new System.Windows.Forms.TextBox(); this.label11 = new System.Windows.Forms.Label(); this.txtZOffset = new System.Windows.Forms.TextBox(); @@ -55,10 +57,6 @@ private void InitializeComponent() this.label8 = new System.Windows.Forms.Label(); this.rApplyZPitch = new System.Windows.Forms.RadioButton(); this.rApplyZRoll = new System.Windows.Forms.RadioButton(); - this.panel1 = new System.Windows.Forms.Panel(); - this.label7 = new System.Windows.Forms.Label(); - this.rLineTypeSpline = new System.Windows.Forms.RadioButton(); - this.rLineTypeLinear = new System.Windows.Forms.RadioButton(); this.label6 = new System.Windows.Forms.Label(); this.txtAngleOffset = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); @@ -75,15 +73,16 @@ private void InitializeComponent() this.chkMassLinkNodes = new System.Windows.Forms.CheckBox(); this.txtCoordList = new System.Windows.Forms.TextBox(); this.cmdCreateEnMasse = new System.Windows.Forms.Button(); - this.label13 = new System.Windows.Forms.Label(); - this.label14 = new System.Windows.Forms.Label(); + this.grpLineType = new System.Windows.Forms.GroupBox(); + this.rLineTypeSpline = new System.Windows.Forms.RadioButton(); + this.rLineTypeLinear = new System.Windows.Forms.RadioButton(); this.groupBox2.SuspendLayout(); this.grpCreateThings.SuspendLayout(); this.panel3.SuspendLayout(); this.panel2.SuspendLayout(); - this.panel1.SuspendLayout(); this.grpAdjustments.SuspendLayout(); this.grpMassCreate.SuspendLayout(); + this.grpLineType.SuspendLayout(); this.SuspendLayout(); // // cmdAdjustSpeed @@ -170,9 +169,9 @@ private void InitializeComponent() this.groupBox2.Controls.Add(this.label12); this.groupBox2.Controls.Add(this.txtRetagStart); this.groupBox2.Dock = System.Windows.Forms.DockStyle.Top; - this.groupBox2.Location = new System.Drawing.Point(3, 246); + this.groupBox2.Location = new System.Drawing.Point(3, 293); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(278, 62); + this.groupBox2.Size = new System.Drawing.Size(280, 62); this.groupBox2.TabIndex = 25; this.groupBox2.TabStop = false; this.groupBox2.Text = "Retag Path"; @@ -213,7 +212,6 @@ private void InitializeComponent() this.grpCreateThings.Controls.Add(this.panel3); this.grpCreateThings.Controls.Add(this.cmdSelectThingType); this.grpCreateThings.Controls.Add(this.panel2); - this.grpCreateThings.Controls.Add(this.panel1); this.grpCreateThings.Controls.Add(this.label6); this.grpCreateThings.Controls.Add(this.txtAngleOffset); this.grpCreateThings.Controls.Add(this.label5); @@ -222,13 +220,31 @@ private void InitializeComponent() this.grpCreateThings.Controls.Add(this.label4); this.grpCreateThings.Controls.Add(this.cmdCreateThings); this.grpCreateThings.Dock = System.Windows.Forms.DockStyle.Top; - this.grpCreateThings.Location = new System.Drawing.Point(3, 100); + this.grpCreateThings.Location = new System.Drawing.Point(3, 147); this.grpCreateThings.Name = "grpCreateThings"; - this.grpCreateThings.Size = new System.Drawing.Size(278, 146); + this.grpCreateThings.Size = new System.Drawing.Size(280, 146); this.grpCreateThings.TabIndex = 26; this.grpCreateThings.TabStop = false; this.grpCreateThings.Text = "Create Things"; // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(143, 3); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(43, 13); + this.label14.TabIndex = 39; + this.label14.Text = "Offsets:"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(187, 16); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(38, 13); + this.label13.TabIndex = 38; + this.label13.Text = "Height"; + // // txtHOffset // this.txtHOffset.Location = new System.Drawing.Point(190, 32); @@ -260,15 +276,15 @@ private void InitializeComponent() this.panel3.Controls.Add(this.label10); this.panel3.Controls.Add(this.rPlaceMiddle); this.panel3.Controls.Add(this.rPlaceBottom); - this.panel3.Location = new System.Drawing.Point(126, 58); + this.panel3.Location = new System.Drawing.Point(9, 58); this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(146, 38); + this.panel3.Size = new System.Drawing.Size(161, 38); this.panel3.TabIndex = 34; // // rPlaceTop // this.rPlaceTop.AutoSize = true; - this.rPlaceTop.Location = new System.Drawing.Point(98, 16); + this.rPlaceTop.Location = new System.Drawing.Point(103, 16); this.rPlaceTop.Name = "rPlaceTop"; this.rPlaceTop.Size = new System.Drawing.Size(44, 17); this.rPlaceTop.TabIndex = 19; @@ -287,7 +303,7 @@ private void InitializeComponent() // rPlaceMiddle // this.rPlaceMiddle.AutoSize = true; - this.rPlaceMiddle.Location = new System.Drawing.Point(51, 16); + this.rPlaceMiddle.Location = new System.Drawing.Point(55, 16); this.rPlaceMiddle.Name = "rPlaceMiddle"; this.rPlaceMiddle.Size = new System.Drawing.Size(42, 17); this.rPlaceMiddle.TabIndex = 17; @@ -298,7 +314,7 @@ private void InitializeComponent() // this.rPlaceBottom.AutoSize = true; this.rPlaceBottom.Checked = true; - this.rPlaceBottom.Location = new System.Drawing.Point(8, 16); + this.rPlaceBottom.Location = new System.Drawing.Point(6, 16); this.rPlaceBottom.Name = "rPlaceBottom"; this.rPlaceBottom.Size = new System.Drawing.Size(41, 17); this.rPlaceBottom.TabIndex = 16; @@ -350,7 +366,7 @@ private void InitializeComponent() // this.rApplyZPitch.AutoSize = true; this.rApplyZPitch.Checked = true; - this.rApplyZPitch.Location = new System.Drawing.Point(4, 16); + this.rApplyZPitch.Location = new System.Drawing.Point(5, 16); this.rApplyZPitch.Name = "rApplyZPitch"; this.rApplyZPitch.Size = new System.Drawing.Size(49, 17); this.rApplyZPitch.TabIndex = 20; @@ -369,48 +385,6 @@ private void InitializeComponent() this.rApplyZRoll.Text = "Roll"; this.rApplyZRoll.UseVisualStyleBackColor = true; // - // panel1 - // - this.panel1.Controls.Add(this.label7); - this.panel1.Controls.Add(this.rLineTypeSpline); - this.panel1.Controls.Add(this.rLineTypeLinear); - this.panel1.Location = new System.Drawing.Point(10, 58); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(109, 38); - this.panel1.TabIndex = 31; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(3, 0); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(56, 13); - this.label7.TabIndex = 18; - this.label7.Text = "Path Type"; - // - // rLineTypeSpline - // - this.rLineTypeSpline.AutoSize = true; - this.rLineTypeSpline.Checked = true; - this.rLineTypeSpline.Location = new System.Drawing.Point(55, 16); - this.rLineTypeSpline.Name = "rLineTypeSpline"; - this.rLineTypeSpline.Size = new System.Drawing.Size(54, 17); - this.rLineTypeSpline.TabIndex = 17; - this.rLineTypeSpline.TabStop = true; - this.rLineTypeSpline.Text = "Spline"; - this.rLineTypeSpline.UseVisualStyleBackColor = true; - // - // rLineTypeLinear - // - this.rLineTypeLinear.AutoSize = true; - this.rLineTypeLinear.Location = new System.Drawing.Point(3, 16); - this.rLineTypeLinear.Name = "rLineTypeLinear"; - this.rLineTypeLinear.Size = new System.Drawing.Size(54, 17); - this.rLineTypeLinear.TabIndex = 16; - this.rLineTypeLinear.Text = "Linear"; - this.rLineTypeLinear.UseVisualStyleBackColor = true; - this.rLineTypeLinear.CheckedChanged += new System.EventHandler(this.rLineTypeLinear_CheckedChanged); - // // label6 // this.label6.AutoSize = true; @@ -485,9 +459,9 @@ private void InitializeComponent() this.grpAdjustments.Controls.Add(this.label2); this.grpAdjustments.Controls.Add(this.txtUnitLength); this.grpAdjustments.Dock = System.Windows.Forms.DockStyle.Top; - this.grpAdjustments.Location = new System.Drawing.Point(3, 3); + this.grpAdjustments.Location = new System.Drawing.Point(3, 50); this.grpAdjustments.Name = "grpAdjustments"; - this.grpAdjustments.Size = new System.Drawing.Size(278, 97); + this.grpAdjustments.Size = new System.Drawing.Size(280, 97); this.grpAdjustments.TabIndex = 27; this.grpAdjustments.TabStop = false; this.grpAdjustments.Text = "Adjustments"; @@ -518,9 +492,9 @@ private void InitializeComponent() this.grpMassCreate.Controls.Add(this.txtCoordList); this.grpMassCreate.Controls.Add(this.cmdCreateEnMasse); this.grpMassCreate.Dock = System.Windows.Forms.DockStyle.Top; - this.grpMassCreate.Location = new System.Drawing.Point(3, 308); + this.grpMassCreate.Location = new System.Drawing.Point(3, 355); this.grpMassCreate.Name = "grpMassCreate"; - this.grpMassCreate.Size = new System.Drawing.Size(278, 116); + this.grpMassCreate.Size = new System.Drawing.Size(280, 116); this.grpMassCreate.TabIndex = 28; this.grpMassCreate.TabStop = false; this.grpMassCreate.Text = "Mass Node Maker (paste coords)"; @@ -571,33 +545,50 @@ private void InitializeComponent() this.cmdCreateEnMasse.UseVisualStyleBackColor = true; this.cmdCreateEnMasse.Click += new System.EventHandler(this.cmdCreateEnMasse_Click); // - // label13 + // grpLineType // - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(187, 16); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(38, 13); - this.label13.TabIndex = 38; - this.label13.Text = "Height"; + this.grpLineType.Controls.Add(this.rLineTypeSpline); + this.grpLineType.Controls.Add(this.rLineTypeLinear); + this.grpLineType.Dock = System.Windows.Forms.DockStyle.Top; + this.grpLineType.Location = new System.Drawing.Point(3, 3); + this.grpLineType.Name = "grpLineType"; + this.grpLineType.Size = new System.Drawing.Size(280, 47); + this.grpLineType.TabIndex = 29; + this.grpLineType.TabStop = false; + this.grpLineType.Text = "Line Type"; // - // label14 + // rLineTypeSpline // - this.label14.AutoSize = true; - this.label14.Location = new System.Drawing.Point(143, 3); - this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(43, 13); - this.label14.TabIndex = 39; - this.label14.Text = "Offsets:"; + this.rLineTypeSpline.AutoSize = true; + this.rLineTypeSpline.Checked = true; + this.rLineTypeSpline.Location = new System.Drawing.Point(70, 19); + this.rLineTypeSpline.Name = "rLineTypeSpline"; + this.rLineTypeSpline.Size = new System.Drawing.Size(54, 17); + this.rLineTypeSpline.TabIndex = 19; + this.rLineTypeSpline.TabStop = true; + this.rLineTypeSpline.Text = "Spline"; + this.rLineTypeSpline.UseVisualStyleBackColor = true; + // + // rLineTypeLinear + // + this.rLineTypeLinear.AutoSize = true; + this.rLineTypeLinear.Location = new System.Drawing.Point(10, 19); + this.rLineTypeLinear.Name = "rLineTypeLinear"; + this.rLineTypeLinear.Size = new System.Drawing.Size(54, 17); + this.rLineTypeLinear.TabIndex = 18; + this.rLineTypeLinear.Text = "Linear"; + this.rLineTypeLinear.UseVisualStyleBackColor = true; // // fTools // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(284, 425); + this.ClientSize = new System.Drawing.Size(286, 474); this.Controls.Add(this.grpMassCreate); this.Controls.Add(this.groupBox2); this.Controls.Add(this.grpCreateThings); this.Controls.Add(this.grpAdjustments); + this.Controls.Add(this.grpLineType); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.Name = "fTools"; this.Padding = new System.Windows.Forms.Padding(3); @@ -610,12 +601,12 @@ private void InitializeComponent() this.panel3.PerformLayout(); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); this.grpAdjustments.ResumeLayout(false); this.grpAdjustments.PerformLayout(); this.grpMassCreate.ResumeLayout(false); this.grpMassCreate.PerformLayout(); + this.grpLineType.ResumeLayout(false); + this.grpLineType.PerformLayout(); this.ResumeLayout(false); } @@ -640,10 +631,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label8; private System.Windows.Forms.RadioButton rApplyZPitch; private System.Windows.Forms.RadioButton rApplyZRoll; - private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.RadioButton rLineTypeSpline; - private System.Windows.Forms.RadioButton rLineTypeLinear; private System.Windows.Forms.Label label6; private System.Windows.Forms.TextBox txtAngleOffset; private System.Windows.Forms.Label label5; @@ -671,5 +658,8 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtHOffset; private System.Windows.Forms.Label label14; private System.Windows.Forms.Label label13; + private System.Windows.Forms.GroupBox grpLineType; + private System.Windows.Forms.RadioButton rLineTypeSpline; + private System.Windows.Forms.RadioButton rLineTypeLinear; } } \ No newline at end of file diff --git a/fTools.cs b/fTools.cs index 267a984..b831a34 100644 --- a/fTools.cs +++ b/fTools.cs @@ -141,28 +141,57 @@ private void cmdAdjustSpeed_Click(object sender, EventArgs e) { General.Settings.WritePluginSetting("adjlen", unit); foreach (List path in paths) { - if (path.Count < 2) { - General.WriteLogLine("Selected path starting at id #" + path[0].ID + " must have at least 2 points. Path ignored."); - continue; - } - if (!undocreated) { - undocreated = true; - General.Map.UndoRedo.CreateUndo("Adjust path travel time"); - } + if (rLineTypeLinear.Checked) { + if (path.Count < 2) { + General.WriteLogLine("Selected path starting at id #" + path[0].ID + " must have at least 2 points. Path ignored."); + continue; + } - PathNode current = path[0]; - List dupelist = new List(); - do { - if (current.Next != null) { - float length = (current.Next.Position - current.Position).GetLength(); - current.TravelTime = (int)Math.Round(length * ticsperunit); - if (current.TravelTime < 1) - current.TravelTime = 1; + if (!undocreated) { + undocreated = true; + General.Map.UndoRedo.CreateUndo("Adjust path travel time"); + } + + PathNode current = path[0]; + List dupelist = new List(); + do { + if (current.Next != null) { + float length = (current.Next.Position - current.Position).GetLength(); + current.TravelTime = (int)Math.Round(length * ticsperunit); + if (current.TravelTime < 1) + current.TravelTime = 1; + + dupelist.Add(current); + } + current = current.Next; + } while (current != null && !dupelist.Contains(current)); + } else { + if (path.Count < 4) { + General.WriteLogLine("Selected path starting at id #" + path[0].ID + " must have at least 4 points in spline mode. Path ignored."); + continue; + } - dupelist.Add(current); + if (!undocreated) { + undocreated = true; + General.Map.UndoRedo.CreateUndo("Adjust path travel time"); } - current = current.Next; - } while (current != null && !dupelist.Contains(current)); + + PathNode last = path[0]; + PathNode current = path[1]; + List dupelist = new List(); + do { + if (current.Next != null && current.Next.Next != null) { + float length = MeasureArcLength(last); + current.TravelTime = (int)Math.Round(length * ticsperunit); + if (current.TravelTime < 1) + current.TravelTime = 1; + + dupelist.Add(current); + } + last = current; + current = current.Next; + } while (current != null && !dupelist.Contains(current)); + } } if (undocreated) { @@ -254,6 +283,33 @@ private float lerp(float t, float p1, float p2) { return p1 + t * (p2 - p1); } + private float MeasureArcLength(PathNode p1) + { + int slices = 10; + float step = 1f / slices; + float t = 0; + float length = 0; + Vector3D last; + + //Must have enough points to construct the arc + if (p1 == null || p1.Next == null || p1.Next.Next == null || p1.Next.Next.Next == null) + return 0; + + last = p1.Next.Position; + for (int i = 1; i <= slices; i++) { + t = step * i; + Vector3D p = new Vector3D( + splerp(t, p1.Position.x, p1.Next.Position.x, p1.Next.Next.Position.x, p1.Next.Next.Next.Position.x), + splerp(t, p1.Position.y, p1.Next.Position.y, p1.Next.Next.Position.y, p1.Next.Next.Next.Position.y), + splerp(t, p1.Position.z, p1.Next.Position.z, p1.Next.Next.Position.z, p1.Next.Next.Next.Position.z) + ); + length += (p - last).GetLength(); + last = p; + } + + return length; + } + private void cmdCreateThings_Click(object sender, EventArgs e) { List> paths = GetSelectedPaths(); if (paths.Count == 0) { diff --git a/fTools.resx b/fTools.resx index 7080a7d..1af7de1 100644 --- a/fTools.resx +++ b/fTools.resx @@ -112,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file