Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input Spline Shape @ Runtime
#1
How do I assign an InputSplineShape at runtime?  I want to have a road that contains 2 lines with a yellow line running down the middle.  Now I want to expand it to a divided highway.  To do this, I need to change the shape and the texture.  How do I assign/reassign the shape, because this doesn't work as I expected it to.  Do I need to use a method instead?  if so what?

                        InputSplineShape SHAPE = GENERATOR.AddModule<InputSplineShape>();
                        SHAPE.FreeForm = true;
                        SHAPE.Shape = Road[0];

Where Road[0] is a CurvySpline and the two lane road shape and Road[1] is the divided highway shape.

                        var RECTANGLE = SHAPE.SetManagedShape<CSRectangle>();
                        RECTANGLE.Width = 40;
                        RECTANGLE.Height = 25;

This code gives me a rectangle and the shape is as I expected.  So, how do I assign/reassign the shape at runtime?

Thanks,
El
Reply
#2
For others ... took a while, but I figure this out too.  You create a Generator in the editor and put all your shapes into the editor.  Then create an attribute:

    public InputSplineShape[] Roads;
    
That has a reference to each of the shapes you created in the ditor.

During runtime, after you've constructed the generator, you copy the appropriate shape to the generator for the shape of the road.
    
    var GENERATOR = CurvyGenerator.Create();
    var SHAPE = Roads[0].CopyTo(GENERATOR);

As for the materials, simply assign it to the volume:

    var VOLUME = GENERATOR.AddModule<BuildVolumeMesh>();
    VOLUME.SetMaterial(0,RoadMaterials[0]);


Jake, any other comments/suggestions?
Reply
#3
Setting InputSplineShape.Shape at runtime should be fine. Note that you need to call CurvyGenerator.Refresh() manually if you want to use the results immediately. Otherwise changes are applied in the next frame's Update() loop.
Reply
#4
Still refuses to work:

Code:
var GENERATOR = CurvyGenerator.Create();
var SHAPE = GENERATOR.AddModule<InputSplineShape>();
SHAPE.Shape = CurvySpline.Create(Rails[0].Shape);
SHAPE.Initialize();

// Other initialization code (see other thread)

GENERATOR.Refresh(true);
GameObject NEW_MESH = aMesh.SaveToScene();

// NEW_MESH is null
Reply
#5
Hello?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Filling a closed spline dynamically rickgplus 1 225 04-16-2025, 08:56 AM
Last Post: _Aka_
  Absolute offset for shape extrudes rickgplus 1 235 03-21-2025, 12:37 PM
Last Post: _Aka_
  Disable a spline's gizmo when not selected or disabled. mikechr2000 1 284 02-03-2025, 09:34 AM
Last Post: _Aka_
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 1,087 01-20-2025, 12:25 PM
Last Post: _Aka_

Forum Jump: