Download

Spline Mesh - Fix mesh scaling?

I’m trying to use construction script to place a train track along a spline but I’ve noticed that if there’s uneven distance between two spline points, it either squashes or stretches the mesh and it looks terrible. I was wondering if there’s a way to fix this so the mesh will be the correct scale regardless of the number of points.

And here’s my construction script:

Is there really no way to fix this issue?

Well, you have to distribute your Spline Points in a uniform manner.

Lol. Yeah, that much I gathered. I was hoping there was a way to automate the process rather than having to do it manually. I guess there isn’t. I think what I’ll do is a combination of using this spline “extrusion” for the rails and then spacing a mesh along the spline for the slats in between the rails. Cause unless you’re literally measuring the spaces between spline points, then there’s going to be squashing and stretching regardless.

What I do is:

  1. create the spline that you want, it doesn’t matter if it has uneven spacing. (this is the spline you can edit in world)
  2. In the construction script create a second spline getting the points from the first spline at an even distance by using Get Location and Tangent at Distance along Spline. (this is the spline mesh you use to construct the tracks and will be invisible). Iterate through this points and create the spline meshes.
  3. Let the mesh and distance be a variables so you can use to other stuff (like a pipeline).
  4. When doing (2) change how you get the points and tangents to make different effects (like a track that always point down or that has a constant elevation).

Oh, that’s a really neat approach Alex. Thank you for sharing your methodology!

It’s a bit late for your problem, but maybe this can help someone else in the future…

There are nodes to get location and tangent at a distance along a spline, instead of getting them only at spline points.
If you know the best looking lenght of your mesh, divide the total lenght of your spline by the ideal lenght of your mesh and make a for each loop on the result, with a add spline mesh node, and set start and end of these spline mesh from locations and tangents at distance along spline calculated by index (for the start) and index+1 (for the end) of the mesh multiplied by the lenght of the mesh.

The downside of this method is that at the end of the spline, your last mesh is not ending exactly at the end of your spline… You should be able to make a division a bit more complicated to obtain the exact number of mesh to fill the spline, while adapting dinamycally the lenght of the mesh… But the simple method was enough for my need.

I came across this thread while looking into why my vertices are not evenly distributed within a spline mesh component and realised that the issue is relating to the tangents. This fix works with splines where several meshes are created along the spline, based on its length divided by the length of the mesh (e.g 200) units.

I have come up with a fix (which works in my case, and I would assume many other cases):
We need to normalize the start and end tangents for each mesh and multiply that vector then by the X length of the mesh component you are using in cm (e.g 2m mesh = 200 in my case)

In my case below, the “Mesh” is just a public variable so I can change it in the scene per instance. It is also possible to get this Mesh’s bounding box size, and multiply the X value by 2 to get the length!

3 Likes