How to generate a curve from a model ?

I have a road model which is a long looped curve made in Blender then exported to FBX.

To make this model, I have created a path and then repeated a portion of road all over it.

Now for my game, I need to get this path back so I can create two lanes for my IAs and player to follow.

I would like to know if it would be possible to extract this path from the model topology via script and if so how ?

That would be ideal so that when I make changes to my model, the paths can be recreated again automatically.

If not possible I’d like to know how I could create those paths otherwise visually in the editor ?

This is the model I’m talking about :

In order for it to be possible the mesh would have to follow some very strict conventions about order of vertices, how they’re paired, etc. So that a pattern could be recognised and you could somehow iterate over mesh sections and take sections’ mid-points as you spline’s key points. Something tells me this mesh is not one of such. And analysing ambiguously modelled mesh — you don’t want to be there with your game, unless you’re working on a next PhD about topologies etc.

What I advise instead is to flip you workflow. Don’t base an abstract mathematical model on a fuzzy human-made mesh. Create the spline first and generate the road mesh (perhaps by “skinning” the spline with mesh segments) from it then. This will solve the problem of analytical representation of your road as well as will dramatically improve iterations on adjusting curvatures etc. In fact such approach is very “traditional”.

Not the worst scenario (looking at the complexity of your track) would also be to create the spline by hand with the road being under it as a visual guide.

Hope this helps.

Since you probably have unwrapped your mesh it should be relatively simple to follow an edge loop along your road by looking at the UV coordinates to determine which neighbor vertex is the next one. So depending on the orientation of your UV map you have to look for a connected edge which second point has a greater / smaller UV value along the road direction.

For this approach all you have to do to start is to pick a start-vertex and move along the edges. That start point could be determined by doing a raycast against a meshcollider. However it also depends on your actual topography of your mesh and where you have edges.