If I understand correctly, you want only 1 mesh to be always at the end? I had that problem too so I made a spot generator given the percent in 0.0 to 1.0 format:
Here's the code:
And the editor script for it:
Here's the code:
Code:
using System;
using UnityEngine;
using System.Collections.Generic;
using FluffyUnderware.Curvy.Pools;
using FluffyUnderware.DevTools;
using ToolBuddy.Pooling.Collections;
namespace FluffyUnderware.Curvy.Generator.Modules
{
[ModuleInfo("Build/Percent Path Spot", ModuleName="Percent Path Spot", Description="Return spots from the path using its TF (0.5 will return a spot in the middle of the path).")]
public class BuildPercentPathSpot : CGModule
{
[HideInInspector]
[InputSlotInfo(typeof(CGPath), Name = "Path/Volume", DisplayName = "Volume/Rasterized Path")]
public CGModuleInputSlot InPath = new CGModuleInputSlot();
[HideInInspector]
[OutputSlotInfo(typeof(CGSpots))]
public CGModuleOutputSlot OutSpots = new CGModuleOutputSlot();
[Serializable]
public struct Entry
{
[RangeEx(0, 1, Label="Percent")]
public float Percent;
[VectorEx]
public Vector3 PositionOffset;
[VectorEx]
public Vector3 RotationOffset;
}
#region ### Serialized Fields ###
[SerializeField]
private List<Entry> m_Entries = new List<Entry>();
#endregion
#region ### Unity Callbacks ###
/*! \cond UNITY */
protected override void OnEnable()
{
base.OnEnable();
// Note: Float Range Sliders won't show up unless we do this:
Properties.MinWidth = 270;
Properties.LabelWidth = 100;
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
Dirty = true;
}
#endif
public override void Reset()
{
base.Reset();
m_Entries.Clear();
m_Entries.Add(new Entry());
}
/*! \endcond */
#endregion
#region ### Module Overrides ###
public override void Refresh()
{
base.Refresh();
/* Add Module processing code in here */
CGPath path = InPath.GetData<CGPath>(out bool isDisposable);
SubArrayList<CGSpot> spots = new SubArrayList<CGSpot>(m_Entries.Count, ArrayPools.CGSpot);
for (int n = 0, len = m_Entries.Count; n < len; ++n)
{
path.Interpolate(m_Entries[n].Percent, out Vector3 pos, out Vector3 dir, out Vector3 up);
Quaternion rotation = Quaternion.LookRotation(dir, up) * Quaternion.Euler(m_Entries[n].RotationOffset);
spots.Add(new CGSpot(0, pos + (rotation * m_Entries[n].PositionOffset), rotation, Vector3.one));
}
OutSpots.SetData(new CGSpots(spots.ToSubArray()));
if (isDisposable)
path.Dispose();
}
// Called when a module's state changes (Link added/removed, Active toggles etc..)
public override void OnStateChange()
{
base.OnStateChange();
if (!IsConfigured)
Clear();
}
public void Clear()
{
OutSpots.SetData(new CGSpots());
}
#endregion
}
}
And the editor script for it:
Code:
using UnityEditor;
using FluffyUnderware.Curvy.Generator.Modules;
namespace FluffyUnderware.CurvyEditor.Generator.Modules
{
[CustomEditor(typeof(BuildPercentPathSpot))]
public class BuildPercentPathSpotEditor : CGModuleEditor<BuildPercentPathSpot>
{
}
}