Thanks, here's the code:
Here is the editor script for it:
Code:
using System;
using UnityEngine;
namespace FluffyUnderware.Curvy.Generator.Modules
{
[ModuleInfo("Modifier/Expand\u200A\u2215\u200AContract Path", ModuleName="Expand/Contract Path", Description="")]
public class ModifierExpandContractPath : CGModule, IOnRequestProcessing, IPathProvider
{
[HideInInspector]
[InputSlotInfo(typeof(CGPath), Name = "Input Path", ModifiesData = true)]
public CGModuleInputSlot InPath = new CGModuleInputSlot();
[HideInInspector]
[OutputSlotInfo(typeof(CGPath), Name = "Modified Path")]
public CGModuleOutputSlot OutPath = new CGModuleOutputSlot();
#region ### Serialized Fields ###
[SerializeField]
[Tooltip("Distance of expansion/contraction. Negative values are ok.")]
float m_Amount;
[SerializeField]
[Tooltip("Angle in degrees to spin the new path about the original path.")]
float m_AngleOffset;
#endregion
#region ### Public Properties ###
public float Amount
{
get => m_Amount;
set
{
if (Math.Abs(m_Amount - value) > Mathf.Epsilon)
{
m_Amount = value;
Dirty = true;
}
}
}
public float AngleOffset
{
get => m_AngleOffset;
set
{
if (Math.Abs(m_AngleOffset - value) > Mathf.Epsilon)
{
m_AngleOffset = value;
Dirty = true;
}
}
}
public bool PathIsClosed => IsConfigured && InPath.SourceSlot().PathProvider.PathIsClosed;
#endregion
#region ### Unity Callbacks ###
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
Dirty = true;
}
#endif
public override void Reset()
{
base.Reset();
Amount = 0;
AngleOffset = 0;
}
#endregion
static readonly Quaternion s_Right = Quaternion.Euler(0, -90, 0);
#region ### IOnRequestProcessing ###
public CGData[] OnSlotDataRequest(CGModuleInputSlot requestedBy, CGModuleOutputSlot requestedSlot, params CGDataRequestParameter[] requests)
{
CGData[] result;
if (requestedSlot == OutPath)
{
CGPath data = InPath.GetData<CGPath>(out bool isDisposable, requests);
#if CURVY_SANITY_CHECKS
Assert.IsTrue(data == null || isDisposable);
#endif
if (data != null && m_Amount != 0)
{
for (int i = 0; i < data.Count; i++)
{
// Direction is forward, so we need to rotate it to the right, we also spin it around by the angle offset
Quaternion rot = Quaternion.LookRotation(data.Directions.Array[i], data.Normals.Array[i]) *
Quaternion.Euler(0, 0, 90+m_AngleOffset) * s_Right;
data.Positions.Array[i] += rot * (Vector3.forward * m_Amount);
}
data.Recalculate();
}
result = new CGData[] { data };
}
else
result = null;
return result;
}
#endregion
}
}
Here is the editor script for it:
Code:
using UnityEditor;
using FluffyUnderware.Curvy.Generator.Modules;
namespace FluffyUnderware.CurvyEditor.Generator.Modules
{
[CustomEditor(typeof(ModifierExpandContractPath))]
public class ModifierExpandContractPathEditor : CGModuleEditor<ModifierExpandContractPath>
{
}
}