Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested Spline Volume Spot Instantiation
#1
[Using Curvy Splines 8.9.1 on Unity 2022.3.35f1]

Hello! 

First, I want to say excellent work on curvy splines! I found the node editor very powerful and easy to learn. However, I'm uncertain if curvy splines is capable of handling my use case.

For my project, I'm creating procedural support rails for a marble to roll down. My project is for rendering video, not a game, so I don't care about performance.

[Image: l1xdjoc]

The main two rails spawn nested prefab gameobjects using the volume spots, which themselves contain more curvy splines for the support rails that connect the two wires and connect them to the wall. 

When I create a new Rail like this, the first problem I see is that a ton of additional meshes are created unnecessarily (you can see the bottom left in the hierarchy. I'm not sure why or where Curvy is generating them. Do you have any idea how I could fix this?

I am also passing information to these newly instantiated support gameobjects (how wide apart the rail is, how thick is the wire)

Code:
    public void Initialize(List<Vector3> points, float wireRadius, float railSeparationDist)
    {
        //_generator.gameObject.SetActive(true);

        MainWirePath.Clear();
        MainWirePath.Add(points.ToArray());

        WireRadius = wireRadius;
        RailSeparationDist = railSeparationDist;

        GenerateRail();
    }

    public List<Collider> GetColliders()
    {
        return GetComponentsInChildren<Collider>().ToList();
    }


    public void OnGeneratorRefresh(CurvyCGEventArgs e)
    {
        Debug.Log("Refresh detected: " + e.Sender.name);
    }

    private void GenerateRail()
    {
        // Check if we are in the prefab editor stage, if so, return
        if (PrefabStageUtility.GetCurrentPrefabStage() != null)
        {
            _generator.gameObject.SetActive(false);
            return;
        }
        if(PrefabUtility.IsAnyPrefabInstanceRoot(gameObject))
            PrefabUtility.UnpackPrefabInstance(this.gameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);

        //Rotate each point in the spline so that in the x y plane the normal always faces away from the curve on the same side
        // Calculate tangents and normals
        for (int i = 0; i < MainWirePath.ControlPointsList.Count; i++)
        {
            Vector3 tangent = MainWirePath.GetTangent(i / (float)MainWirePath.ControlPointsList.Count).normalized;
            Vector3 normal = new Vector3(-tangent.y, tangent.x, 0).normalized; // Perpendicular in the XY plane

            Debug.DrawRay(MainWirePath.ControlPointsList[i].transform.position, tangent, Color.yellow, 10);
            Debug.DrawRay(MainWirePath.ControlPointsList[i].transform.position, normal, Color.magenta, 10);

            Quaternion rotation = Quaternion.LookRotation(Vector3.forward, normal);
            MainWirePath.ControlPointsList[i].SetLocalRotation(rotation);
        }
        //_generator.Refresh(forceUpdate: true);

        Debug.Log("Is generator initialized: " + _generator.IsInitialized);

        _trsMesh1.Transpose = new Vector3(0, 0, -RailSeparationDist / 2f); //For some reason only works when I set the transpose this way
        _trsMesh2.Transpose = new Vector3(0, 0, RailSeparationDist / 2f);

        _mainRailShapeExtrusion.ScaleX = WireRadius;

        if (_buildVolumeSpots.GroupCount > 0)
        {
            var spaceBefore = _buildVolumeSpots.Groups[0].SpaceBefore;
            spaceBefore.Clamp(_spaceBeforeConnectors, _spaceBeforeConnectors);
            _buildVolumeSpots.Groups[0].SpaceBefore = spaceBefore;
        }
        else
            Debug.LogError("Missing group in volume spots");

        //_createGameObject.Refresh(); // I think I need this. Gameobjects are stale after changing the build volume spots

        //_generator.Refresh(forceUpdate: true);

        foreach(var railSupport in GetComponentsInChildren<RailSupport>())
            railSupport.UpdateSupport(WireRadius, RailSeparationDist);

    }

Basically, I'm not sure how to safely handle nested curvysplines inside volume spot create gameobject. 

Additionally, my script is also spawning in these rails at runtime, so I am storing them in prefabs. However, even with auto refresh turned off, the generator still refreshes every time I open the prefab and creates all the spot gameobjects and meshes, which I then have to manually delete to prevent errors from curvy trying to delete parts of a prefab when refreshing. What is the best practice for handling storing a curvy spline intended for procedural generation use as a prefab?

Any help or advice would be much appreciated!
Reply
#2
Hi

(07-22-2024, 02:28 PM)merobbins5 Wrote: When I create a new Rail like this, the first problem I see is that a ton of additional meshes are created unnecessarily (you can see the bottom left in the hierarchy. I'm not sure why or where Curvy is generating them. Do you have any idea how I could fix this?

I am not sure about what is happening there, but I "feel" it is triggered by nesting generators. Let's put this aside for a moment, solve the other problem, and then come back to it if still unsolved.

(07-22-2024, 02:28 PM)merobbins5 Wrote: What is the best practice for handling storing a curvy spline intended for procedural generation use as a prefab?

I would recommend to do the following:
- Add to the scene the generator A that generates the rail support gameobjects.
- Those game objects should contain only the rail support mesh and their associated spline to be modified, no other generators.
- Have a script on a separate GO that will be triggered at each generator A's refresh, and will generate and/or update a multitude of generators B, one for each support spline.
- I suggest, to avoid complications with prefabs, to use Templates to store your generator B and load it. You can load templates at runtime using CGEditorUtility.LoadTemplate
More about templates: https://curvyeditor.com/documentation/ge.../templates

I hope this helped.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
(07-23-2024, 02:23 PM)_Aka_ Wrote: Hi

(07-22-2024, 02:28 PM)merobbins5 Wrote: When I create a new Rail like this, the first problem I see is that a ton of additional meshes are created unnecessarily (you can see the bottom left in the hierarchy. I'm not sure why or where Curvy is generating them. Do you have any idea how I could fix this?

I am not sure about what is happening there, but I "feel" it is triggered by nesting generators. Let's put this aside for a moment, solve the other problem, and then come back to it if still unsolved.

(07-22-2024, 02:28 PM)merobbins5 Wrote: What is the best practice for handling storing a curvy spline intended for procedural generation use as a prefab?

I would recommend to do the following:
- Add to the scene the generator A that generates the rail support gameobjects.
- Those game objects should contain only the rail support mesh and their associated spline to be modified, no other generators.
- Have a script on a separate GO that will be triggered at each generator A's refresh, and will generate and/or update a multitude of generators B, one for each support spline.
- I suggest, to avoid complications with prefabs, to use Templates to store your generator B and load it. You can load templates at runtime using CGEditorUtility.LoadTemplate
More about templates: https://curvyeditor.com/documentation/ge.../templates

I hope this helped.

I didn't realize templates could be instantiated at runtime. Thank you for the reply I will give that a try!
Reply
#4
You are welcome. If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Disable a spline's gizmo when not selected or disabled. mikechr2000 1 141 02-03-2025, 09:34 AM
Last Post: _Aka_
Photo Volume Spots problem with spacing Bond007 3 218 01-20-2025, 12:27 PM
Last Post: _Aka_
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 515 01-20-2025, 12:25 PM
Last Post: _Aka_
  Extrude mesh along spline. New and confused user GhostStalker 3 215 01-02-2025, 09:58 AM
Last Post: _Aka_

Forum Jump: