07-22-2024, 02:28 PM
[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]](https://imgur.com/a/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)
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!
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.
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!