I want to provide some CGModule-extending code in a public repository for other Curvy users to use. They will be able to use it by adding FLUFFYUNDERWARE_CURVY to their Scripting Define Symbols, found under Edit > Project Settings > Player, in the inspector window.
This is adapted from the ModifierTRSPath class.
ModifierOffsetPath.cs
ModifierOffsetPathEditor.cs
Am I allowed to make this source code publicly available in my repository?
PS: If you want to add these to/adapt these for Curvy, please go ahead. You have my full permission!
This is adapted from the ModifierTRSPath class.
ModifierOffsetPath.cs
Code:
// =====================================================================
// Copyright 2013-2017 Fluffy Underware
// All rights reserved
//
// http://www.fluffyunderware.com
// =====================================================================
#if FLUFFYUNDERWARE_CURVY
using FluffyUnderware.DevTools;
using UnityEngine;
namespace FluffyUnderware.Curvy.Generator.Modules
{
[ModuleInfo("Modifier/Offset Path", ModuleName = "Offset Path", Description = "Offset a path by its normals/binormals")]
[HelpURL(CurvySpline.DOCLINK + "cgtrspath")]
public class ModifierOffsetPath : CGModule, IOnRequestPath
{
[HideInInspector]
[InputSlotInfo(typeof(CGPath), Name = "Path A", ModifiesData = true)]
public CGModuleInputSlot InPath = new CGModuleInputSlot();
[HideInInspector]
[OutputSlotInfo(typeof(CGPath))]
public CGModuleOutputSlot OutPath = new CGModuleOutputSlot();
#region ## Serialized Fields ##
[SerializeField]
[VectorEx]
private Vector3 m_Offset;
#endregion ## Serialized Fields ##
#region ### Public Properties ###
public Vector3 Offset
{
get { return m_Offset; }
set
{
if (m_Offset != value)
m_Offset = value;
Dirty = true;
}
}
public float PathLength
{
get
{
return (IsConfigured) ? InPath.SourceSlot().OnRequestPathModule.PathLength : 0;
}
}
public bool PathIsClosed
{
get
{
return (IsConfigured) ? InPath.SourceSlot().OnRequestPathModule.PathIsClosed : false;
}
}
#endregion ### Public Properties ###
#region ### IOnRequestProcessing ###
public CGData[] OnSlotDataRequest(CGModuleInputSlot requestedBy, CGModuleOutputSlot requestedSlot, params CGDataRequestParameter[] requests)
{
if (requestedSlot == OutPath)
{
var Data = InPath.GetData<CGPath>(requests);
for (int i = 0; i < Data.Count; i++)
{
var position = Data.Position[i];
var tangent = Data.Direction[i];
var normal = Data.Normal[i];
var binormal = Vector3.Cross(tangent, normal);
var offset_matrix = new Matrix4x4();
offset_matrix.SetColumn(0, tangent);
offset_matrix.SetColumn(1, normal);
offset_matrix.SetColumn(2, binormal);
Vector3 offset = offset_matrix * Offset;
Data.Position[i] += offset;
}
Data.Recalculate();
return new CGData[1] { Data };
}
return null;
}
#region ### Unity Callbacks ###
/*! \cond UNITY */
protected override void OnEnable()
{
base.OnEnable();
Properties.MinWidth = 200;
Properties.LabelWidth = 50;
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
Offset = m_Offset;
}
#endif
/*! \endcond */
#endregion ### Unity Callbacks ###
}
#endregion ### IOnRequestProcessing ###
}
#endif
ModifierOffsetPathEditor.cs
Code:
// =====================================================================
// Copyright 2013-2017 Fluffy Underware
// All rights reserved
//
// http://www.fluffyunderware.com
// =====================================================================
#if FLUFFYUNDERWARE_CURVY
using FluffyUnderware.Curvy.Generator.Modules;
using UnityEditor;
namespace FluffyUnderware.CurvyEditor.Generator.Modules
{
[CustomEditor(typeof(ModifierOffsetPath))]
public class ModifierOffsetPathEditor : CGModuleEditor<ModifierOffsetPath>
{
}
}
#endif
Am I allowed to make this source code publicly available in my repository?
PS: If you want to add these to/adapt these for Curvy, please go ahead. You have my full permission!