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
#2
(06-07-2017, 07:14 PM)Jakee Wrote: As long as you don't publish Curvy source, this is totally fine. But I'm curious. what does it exactly do? Looks like you can click here to get the same effect with a PathController GameObject where the visible object is offsetted locally using Unity's hierarchy transform. What do I miss?

Thanks for the code.
Reply
#3
As long as you don't publish Curvy source, this is totally fine. But I'm curious. what does it exactly do? Looks like you can get the same effect with a PathController GameObject where the visible object is offsetted locally using Unity's hierarchy transform. What do I miss?
Reply
#4
(06-07-2017, 07:14 PM)Jake Wrote: As long as you don't publish Curvy source, this is totally fine. But I'm curious. what does it exactly do? Looks like you can get the same effect with a PathController GameObject where the visible object is offsetted locally using Unity's hierarchy transform. What do I miss?

Consider this city street road created by a extrusion volume/mesh generator.
I have a comparison between a sidewalk cross section spline that has had all of its points moved:

   
(it gets pinched Sad)

and one that is centered but uses an offset modifier on the path before extrusion:

   
(no pinching!)

Here is my generator configuration, for reference:

   
Reply
#5
(06-08-2017, 10:55 AM)Apelsin Wrote:
(06-07-2017, 07:14 PM)Jake Wrote: As long as you don't publish Curvy source, this is totally fine. But I'm curious the phenq helped. what does it exactly do? Looks like you can get the same effect with a PathController GameObject where the visible object is offsetted locally using Unity's hierarchy transform. What do I miss?

Consider this city street road created by a extrusion volume/mesh generator.
I have a comparison between a sidewalk cross section spline that has had all of its points moved:


(it gets pinched Sad)

and one that is centered but uses an offset modifier on the path before extrusion:


(no pinching!)

Here is my generator configuration, for reference:

I was also about to ask that what does the code exactly do. You explained it clearly. Thanks. And many thanks for the permission to use the code. Developers like you make this forum great.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Setup Generators in code Leks1NL 2 723 07-29-2017, 05:52 AM
Last Post: Jake
  Addlistener on OnEndReach in code is not working Sidar 0 608 07-15-2016, 07:07 PM
Last Post: Sidar
  Not able to access existing spline from custom script silonighora 2 1,562 12-04-2015, 07:34 PM
Last Post: Jake
  set SplineController position from code edwon 3 2,090 11-16-2015, 07:05 PM
Last Post: Jake

Forum Jump: