I’ve looked at the playground and the documentation page you’ve created @JohnK It’s very well documented! Also with options to specify how you want the track between the points to lean and wave. This will definitely help more users get some kind of rollercoaster into their app or some scenic camera movement play.
I have the idea that in my game http://www.geektrains.com I take the rail track building from a different approach. It’s just different, not better or worse. The recipe is as follows: I take a carriage, or actually a wheel axle (which is bound to the track), and draw a set (trace) of points in 3D world space by moving that wheel axle around in local space. When I want it to turn (around world Y axis) to create a track circle for example, I create a pivot point (or actually, a PivotMesh) to the left or right of it’s local space point and move the wheel axle mesh using the inbuild rotate around pivot function.
I chose this approach simply because it is then easier for me to describe a railroad track in a game level: as if you were laying fixed track parts (straight track parts, left and right curve track parts) and connecting them to each other in an array. Very intuitive to buying model train track in a store and then placing it in a layout at home. This saves the level editor on have to know all the 3D world points beforehand (which was a difficult thing to do in more complex track layouts). One just takes a starting point and direction in 3D world space and then starts placing straight and curved tracks from that point onward to one’s desire.
The lean in my top-down (XZ-plane) approach increases when I create a Path which both turns (Y rotation) and rises/lowers (Y location). The lean comes from the Normals, Binormals and Tangents derived from the Path. So with some math tweaking taken from your sample code I might be able to restore the lean (e.g. remove the inward lean on the end of a helix curve). So it’s great to have an example now which contains many of the direction and rotation Math I’ll be needing to adjust for the built in Tangents, Normals and Binormals of Path3D.
Also the lean and waves options are a funny feature to introduce on my game railroad tracks. It will definitely add to the fun!
If you want to go more complex/advanced here are some ideas: make a train (several carriages in a row, following the track), add points/turnouts/switches (a track can split into 2 tracks etc.), add bogeys under carriages (definitely some challenging math in curves as the bogey wheel axles are tied to the track and the carriage length is fixed to the bogeys center, but not straight above the track any more).
Happy coding and thanks again for taking the time to write a doc on it!