diff --git a/Source/ProceduralAbstractShape.cs b/Source/ProceduralAbstractShape.cs
index a6fa875..79a03d2 100644
--- a/Source/ProceduralAbstractShape.cs
+++ b/Source/ProceduralAbstractShape.cs
@@ -151,6 +151,11 @@ protected set
}
private float _length;
+ ///
+ /// Key that will uniquely identify the geometry of the current shape.
+ ///
+ public abstract string ShapeKey { get; }
+
#endregion
#region Events
diff --git a/Source/ProceduralPart.cs b/Source/ProceduralPart.cs
index 03625a0..bba3a75 100644
--- a/Source/ProceduralPart.cs
+++ b/Source/ProceduralPart.cs
@@ -5,6 +5,7 @@
using KSPAPIExtensions;
using System.Reflection;
using UnityEngine.Profiling;
+using ROUtils;
namespace ProceduralParts
{
@@ -599,10 +600,9 @@ public void OnPartColliderChanged()
// Drag cubes should get generated immediately during the partcatalog compilation stage;
// in all other cases there may need to be a delay.
if (PartLoader.Instance.IsReady())
- ProceduralTools.DragCubeTool.UpdateDragCubes(part);
+ DragCubeTool.UpdateDragCubes(part, CurrentShape.ShapeKey);
else
- ProceduralTools.DragCubeTool.UpdateDragCubesImmediate(part);
-
+ DragCubeTool.UpdateDragCubesImmediate(part, CurrentShape.ShapeKey);
}
}
diff --git a/Source/ProceduralParts.csproj b/Source/ProceduralParts.csproj
index 1b72dfd..33e901c 100644
--- a/Source/ProceduralParts.csproj
+++ b/Source/ProceduralParts.csproj
@@ -65,6 +65,9 @@
false
+
+ False
+
False
@@ -111,7 +114,6 @@
-
diff --git a/Source/ProceduralShapeBezierCone.cs b/Source/ProceduralShapeBezierCone.cs
index e10ad6f..daa4fa8 100644
--- a/Source/ProceduralShapeBezierCone.cs
+++ b/Source/ProceduralShapeBezierCone.cs
@@ -66,6 +66,15 @@ internal class ShapePreset
#endregion
+ public override string ShapeKey
+ {
+ get
+ {
+ string shape = selectedShape != CustomShapeName ? selectedShape : $"{shapePoints.x};{shapePoints.y};{shapePoints.z};{shapePoints.w}";
+ return $"BCone|{topDiameter}|{bottomDiameter}|{length}|{offset}|{shape}";
+ }
+ }
+
#region Helper Funcs
internal const float MaxCircleError = 0.01f;
diff --git a/Source/ProceduralShapeCone.cs b/Source/ProceduralShapeCone.cs
index 3560878..6de34be 100644
--- a/Source/ProceduralShapeCone.cs
+++ b/Source/ProceduralShapeCone.cs
@@ -25,6 +25,8 @@ public class ProceduralShapeCone : ProceduralAbstractSoRShape
#endregion
+ public override string ShapeKey => $"PP-Cone|{topDiameter}|{bottomDiameter}|{length}";
+
#region Limit paramters
///
diff --git a/Source/ProceduralShapeCylinder.cs b/Source/ProceduralShapeCylinder.cs
index c0db099..f215517 100644
--- a/Source/ProceduralShapeCylinder.cs
+++ b/Source/ProceduralShapeCylinder.cs
@@ -18,6 +18,8 @@ public class ProceduralShapeCylinder : ProceduralAbstractSoRShape
#endregion
+ public override string ShapeKey => $"PP-Cyl|{diameter}|{length}";
+
#region Initialization
public override void OnStart(StartState state)
diff --git a/Source/ProceduralShapeHollowCone.cs b/Source/ProceduralShapeHollowCone.cs
index 9526a92..38356f4 100644
--- a/Source/ProceduralShapeHollowCone.cs
+++ b/Source/ProceduralShapeHollowCone.cs
@@ -9,7 +9,7 @@ namespace ProceduralParts
class ProceduralShapeHollowCone : ProceduralAbstractShape
{
private const string ModTag = "[ProceduralShapeHollowCone]";
- public override Vector3 CoMOffset => CoMOffset_internal();
+ private const float maxError = 0.0125f;
#region Config parameters
@@ -39,8 +39,6 @@ class ProceduralShapeHollowCone : ProceduralAbstractShape
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit = "m", useSI = true)]
public float length = 1f;
- private const float maxError = 0.0125f;
-
public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt((Math.Max(bottomOuterDiameter, topOuterDiameter)))/(2f * maxError)), 24);
[KSPField]
@@ -53,6 +51,9 @@ class ProceduralShapeHollowCone : ProceduralAbstractShape
#region Utility Properties
+ public override Vector3 CoMOffset => CoMOffset_internal();
+ public override string ShapeKey => $"PP-HCone|{topOuterDiameter}|{topInnerDiameter}|{bottomOuterDiameter}|{bottomInnerDiameter}|{length}";
+
private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);
diff --git a/Source/ProceduralShapeHollowCylinder.cs b/Source/ProceduralShapeHollowCylinder.cs
index f4afdc9..8e87f8d 100644
--- a/Source/ProceduralShapeHollowCylinder.cs
+++ b/Source/ProceduralShapeHollowCylinder.cs
@@ -9,6 +9,7 @@ namespace ProceduralParts
class ProceduralShapeHollowCylinder : ProceduralAbstractShape
{
private const string ModTag = "[ProceduralShapeHollowCylinder]";
+ private const float maxError = 0.0125f;
#region Config parameters
@@ -27,8 +28,6 @@ class ProceduralShapeHollowCylinder : ProceduralAbstractShape
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit = "m", useSI = true)]
public float length = 1f;
- private const float maxError = 0.0125f;
-
public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt(outerDiameter)/(2f * maxError)), 24);
[KSPField]
@@ -41,6 +40,8 @@ class ProceduralShapeHollowCylinder : ProceduralAbstractShape
#region Utility Properties
+ public override string ShapeKey => $"PP-HCyl|{outerDiameter}|{innerDiameter}|{length}";
+
private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);
diff --git a/Source/ProceduralShapeHollowPill.cs b/Source/ProceduralShapeHollowPill.cs
index 2f3bbd6..8497a15 100644
--- a/Source/ProceduralShapeHollowPill.cs
+++ b/Source/ProceduralShapeHollowPill.cs
@@ -12,6 +12,7 @@ namespace ProceduralParts
class ProceduralShapeHollowPill : ProceduralAbstractShape
{
private const string ModTag = "[ProceduralShapeHollowPill]";
+ private const float maxError = 0.0125f;
[KSPField(guiActiveEditor = true, guiName = "Diameters", groupName = ProceduralPart.PAWGroupName)]
private string diamTitleString = "";
@@ -32,8 +33,6 @@ class ProceduralShapeHollowPill : ProceduralAbstractShape
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit="m", useSI = true)]
public float fillet = 0f;
- private const float maxError = 0.0125f;
-
public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt(outerDiameter)/(2f * maxError)), 24);
public float MajorRadius => (outerDiameter + innerDiameter) / 4;
@@ -48,6 +47,8 @@ class ProceduralShapeHollowPill : ProceduralAbstractShape
private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);
+ public override string ShapeKey => $"PP-HPill|{innerDiameter}|{outerDiameter}|{length}|{fillet}";
+
public override void OnStart(StartState state)
{
base.OnStart(state);
diff --git a/Source/ProceduralShapeHollowTruss.cs b/Source/ProceduralShapeHollowTruss.cs
index 367d64c..28a8f2d 100644
--- a/Source/ProceduralShapeHollowTruss.cs
+++ b/Source/ProceduralShapeHollowTruss.cs
@@ -9,6 +9,7 @@ class ProceduralShapeHollowTruss : ProceduralAbstractShape
{
#region KSPFields
private const string ModTag = "[ProceduralShapeHollowTruss]";
+ private const float maxMeshBendError = 0.02f;
[KSPField(isPersistant = true, guiActiveEditor = true, guiName = "Top D", guiFormat = "F3", guiUnits = "m", groupName = ProceduralPart.PAWGroupName),
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit = "m", useSI = true)]
@@ -61,10 +62,10 @@ public float RealLength
return realLength;
}
}
-
- const float maxMeshBendError = 0.02f;
#endregion
+ public override string ShapeKey => $"PP-HTruss|N{nbRods}{(symmetryRods ? "S" : "")}|{topDiameter}|{bottomDiameter}|{length}|{rodDiameter}|{tiltAngle}|{offsetAngle}";
+
public override void OnStart(StartState state)
{
base.OnStart(state);
diff --git a/Source/ProceduralShapePill.cs b/Source/ProceduralShapePill.cs
index b5f9c8f..5f69787 100644
--- a/Source/ProceduralShapePill.cs
+++ b/Source/ProceduralShapePill.cs
@@ -25,6 +25,8 @@ public class ProceduralShapePill : ProceduralAbstractSoRShape
#endregion
+ public override string ShapeKey => $"PP-Pill|{diameter}|{length}|{fillet}";
+
#region Initialization
public override void OnStart(StartState state)
diff --git a/Source/ProceduralShapePolygon.cs b/Source/ProceduralShapePolygon.cs
index 1cbf49b..7a58ae7 100644
--- a/Source/ProceduralShapePolygon.cs
+++ b/Source/ProceduralShapePolygon.cs
@@ -74,6 +74,7 @@ internal SimPart() { }
// => (0.25 * innerDIameter * innerDiameter * normSideLength * cornerCount)
}
+ public override string ShapeKey => $"PP-Poly|N{cornerCount}|{diameter}|{length}";
private new float Length => length;
private int CornerCount => (int)cornerCount;
private float CornerCenterCornerAngle => 2 * Mathf.PI / CornerCount;
diff --git a/Source/ProceduralTools/DragCubeTool.cs b/Source/ProceduralTools/DragCubeTool.cs
deleted file mode 100644
index 34a5cbe..0000000
--- a/Source/ProceduralTools/DragCubeTool.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-using System;
-using System.Linq;
-using UnityEngine;
-using UnityEngine.Profiling;
-
-namespace ProceduralTools
-{
- public class DragCubeTool : MonoBehaviour
- {
- public Part part;
-
- public static DragCubeTool UpdateDragCubes(Part p)
- {
- var tool = p.GetComponent();
- if (tool == null)
- {
- tool = p.gameObject.AddComponent();
- tool.part = p;
- }
- return tool;
- }
-
- public static void UpdateDragCubesImmediate(Part p)
- {
- if (!Ready(p))
- throw new InvalidOperationException("Not ready for drag cube rendering yet");
-
- UpdateCubes(p);
- }
-
- public void FixedUpdate()
- {
- if (Ready())
- UpdateCubes();
- }
-
- public bool Ready() => Ready(part);
-
- private static bool Ready(Part p)
- {
- if (HighLogic.LoadedSceneIsFlight)
- return FlightGlobals.ready; //&& !part.packed && part.vessel.loaded;
- if (HighLogic.LoadedSceneIsEditor)
- return p.localRoot == EditorLogic.RootPart && p.gameObject.layer != LayerMask.NameToLayer("TransparentFX");
- return true;
- }
-
- private void UpdateCubes()
- {
- UpdateCubes(part);
- Destroy(this);
- }
-
- private static void UpdateCubes(Part p)
- {
- Profiler.BeginSample("UpdateCubes");
- if (FARinstalled)
- p.SendMessage("GeometryPartModuleRebuildMeshData");
- DragCube dragCube = DragCubeSystem.Instance.RenderProceduralDragCube(p);
- p.DragCubes.ClearCubes();
- p.DragCubes.Cubes.Add(dragCube);
- p.DragCubes.ResetCubeWeights();
- p.DragCubes.ForceUpdate(true, true, false);
- p.DragCubes.SetDragWeights();
- Profiler.EndSample();
- }
-
- private static bool? _farInstalled;
- public static bool FARinstalled
- {
- get
- {
- if (!_farInstalled.HasValue)
- {
- _farInstalled = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "FerramAerospaceResearch");
- }
- return _farInstalled.Value;
- }
- }
- }
-}
diff --git a/Source/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs
index d6d6d44..45715c2 100644
--- a/Source/Properties/AssemblyInfo.cs
+++ b/Source/Properties/AssemblyInfo.cs
@@ -42,3 +42,5 @@
#else
[assembly: AssemblyFileVersion("2.99.0.0")]
#endif
+
+[assembly: KSPAssemblyDependency("ROUtils", 1, 1)]