Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Spots Filter Generator Module
#3
Hey Aka, Thanks for your reply. I ended up fixing it myself - it was my bad use of the SubArray<> class where I was using spots.Spots.Array.Count instead of spots.Spots.Count - it was accessing the unused, but allocated elements of the array

For anyone who may want it in the future, here is the fixed code. I note that I had to change the original volume spots generation to use full rotation so the spots are generated at the correct angle for this filter to check their angle, then this module compares the angle to the horizon, filters spots based on that, and then sets the spots to default rotation so they always face the ground.

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>();

            for (int i=0; i<spots.Spots.Count; i++)
            {
                CGSpot spot = spots.Spots.Array[i];
                Vector3 angle = spot.Rotation * Vector3.up;

                float dot = Vector3.Dot(Vector3.up, angle);
                if (dot > 0)
                {
                    spot.Rotation = Quaternion.identity;
                    outSpots.Add(spot);
                }
            }
           
            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()
        //{
        //    return base.DeleteAllOutputManagedResources();
        //}

        #endregion
    }
}
Reply


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

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: