Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Spots Filter Generator Module
#1
Hey,

Trying to write a custom generator node that takes in a set of spots, applies a filter function, and then outputs the new modified list.

In my case, I am filtering based on the rotation to prevent poles on my rollercoaster from connecting to inverted pieces of track.

It seemed to work well when I was using a small test track, but scaling it up to larger tracks I am getting crazy results where its adding hundreds of spots that should not have even been in the original input list? Probably I'm doing something wrong in the node.

Heres my code:

Code:
using UnityEngine;
using System.Collections;
using FluffyUnderware.DevTools;
using System.Collections.Generic;

namespace FluffyUnderware.Curvy.Generator.Modules
{
    [ModuleInfo("Custom/Spot Angle Filter",ModuleName="Spot Angle Filter", Description="Filter spots based on their rotation")]
    public class SpotAngleFilter : CGModule
    {
       
        [HideInInspector]
        [InputSlotInfo(typeof(CGSpots), Name = "Spots", DisplayName = "Spots")]
        public CGModuleInputSlot InData = new CGModuleInputSlot();

        [HideInInspector]
        [OutputSlotInfo(typeof(CGSpots), Name = "Spots", DisplayName = "Spots")]
        public CGModuleOutputSlot OutData = new CGModuleOutputSlot();

        #region ### Serialized Fields ###
        #endregion
        #region ### Public Properties ###

        // Gets whether the module is properly configured i.e. has everything needed to work like intended
        public override bool IsConfigured
        {
            get
            {
                return base.IsConfigured;
            }
        }

        // Gets whether the module and all its dependencies are fully initialized
        public override bool IsInitialized
        {
            get
            {
                return base.IsInitialized;
            }
        }
       
        #endregion

        #region ### Unity Callbacks ###
        /*! \cond UNITY */
        protected override void OnEnable()
        {
            base.OnEnable();
            //Properties.MinWidth = 250;
            //Properties.LabelWidth = 80;
        }

#if UNITY_EDITOR
        protected override void OnValidate()
        {
            base.OnValidate();
        }
#endif

        public override void Reset()
        {
            base.Reset();
        }

        /*! \endcond */
        #endregion

        #region ### Module Overrides ###

        public override void Refresh()
        {
            base.Refresh();
            /* Add Module processing code in here */

            CGSpots spots = InData.GetData<CGSpots>();
            List<CGSpot> outSpots = new List<CGSpot>();

            foreach (CGSpot spot in spots.Spots.Array)
            {
                Vector3 angle = spot.Rotation * Vector3.forward;
                float dot = Vector3.Dot(Vector3.forward, angle);
                if (dot > 0)
                {
                    outSpots.Add(spot);
                    //outSpots.Add(new CGSpot(outSpots.Count, spot.Position, spot.Rotation, spot.Scale)); // doesn't work..
                }

            }

            OutData.ClearData();
            OutData.SetData(new CGSpots(outSpots));

        }

        // Called when a module's state changes (Link added/removed, Active toggles etc..)
        //public override void OnStateChange()
        //{
        //    base.OnStateChange();
        //}

        // Called after a module was copied to a template
        //public override void OnTemplateCreated()
        //{
        //    base.OnTemplateCreated();
        //}

        //Called in multiple situations to clear all the outputs generated by this module. One example is when you click on the "Clear output" button in the Curvy Generator's toolbar
        public override bool DeleteAllOutputManagedResources()
        {
            OutData.ClearData();

            return base.DeleteAllOutputManagedResources();
        }

        #endregion
    }
}
Reply


Messages In This Thread
Custom Spots Filter Generator Module - by mercior - 03-09-2023, 05:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  8.8.0 is live, and it improves Curvy Generator greatly _Aka_ 1 10 04-03-2024, 03:16 PM
Last Post: _Aka_
Exclamation Extending Curvy Generator for Advanced Lofting - Feasibility Check amutp 2 5 03-27-2024, 07:25 AM
Last Post: amutp
  Generating GO only on CPs in Generator GameDeveloperek4123 1 7 03-04-2024, 11:06 AM
Last Post: _Aka_
Question Volume Spots inter group distance Sacryn 1 3 02-27-2024, 04:08 PM
Last Post: _Aka_

Forum Jump: