Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scale Deform Mesh Along Spline? / aligning colliders
#6
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:

[Image: o0Qfkv4.gif]

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;
        #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>
    {
    }
}
Reply


Messages In This Thread
RE: Scale Deform Mesh Along Spline? / aligning colliders - by Ferdinand - 09-19-2022, 11:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Video Scale Mesh at ControlPoints harshad 3 8 Yesterday, 02:11 PM
Last Post: _Aka_
  Multiple Mesh Extrude Generator bakin 1 6 09-17-2022, 12:40 PM
Last Post: _Aka_
  How can I remove one segment of the road that I made by spline? Chanon 3 6 09-14-2022, 04:44 PM
Last Post: _Aka_
  Changing range affects generated mesh GameJazz 7 19 08-19-2022, 08:08 PM
Last Post: _Aka_

Forum Jump: