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 = 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>
    {
    }
}
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
  Incorrect mesh alignment after extrusion on curved path Thinkurvy 10 19 04-17-2024, 10:57 AM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
  Adjust radius of generated mesh via script? Shackman 1 4 03-26-2024, 01:12 PM
Last Post: _Aka_

Forum Jump: