Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Permission to publish custom CGModule source code?
#1
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
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!
Reply


Messages In This Thread
Permission to publish custom CGModule source code? - by Apelsin - 05-23-2017, 08:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to attach custom components to output Sacryn 3 7 02-23-2024, 09:42 AM
Last Post: _Aka_
  Guide to custom placing stuff on spline Lupos 15 43 11-27-2023, 12:51 PM
Last Post: _Aka_
  Custom CurvySplineSegment prefabs Lupos 1 10 10-02-2023, 09:36 AM
Last Post: _Aka_
  Custom Control Nodes Lupos 3 15 05-27-2023, 09:05 PM
Last Post: _Aka_

Forum Jump: