# Train tracks in procedural

## Recommended Posts

Hi

I'm still a beginner in Houdini and i decided to create a mini project to learn it and stay motivated. I want create a procedural train tracks. I would like to have the tracks follow a spline and depending on the angle and the lenght of the spline the system will place the correct blocks. I will build each blocks straight and curve separately.

Here is the schematic of each blocks and a quick render i did in Houdini

Any idea where to start ?

Thomas

• 2

##### Share on other sites

Awesome idea! I’m following this thread, should be a great learning opportunity.

##### Share on other sites
Posted (edited)

This sounds neat! I'm down to offer some help.

Well as with most things in Houdini I think it would be a good to start by breaking our problem down into parts.

So we have the user create a nurbs or bezier curve (not polygon) so that we can resample the curve into evenly spaced lines. Having the lines be evenly spaced will help if/when we calculate the curvature between the re sampled points. What comes next depends on what kind of system we design.

Option 1: We calculate the curvature of the curve and if the points fall within a certain angel threshold they get assigned a value (0, 1, 2...) corresponding to the respective piece.

Option 1.1: After we find what points would get what pieces, we build the whole thing piece by piece. Starting with an initial position and then going through each point, reading which piece, and then appending that piece to the end of the rail. There are problems with this though. Because the system is built around the curvature between two points, it doesn't take into consideration where those two points are meaning that by the end the rails would be very displaced from the original curve.

Option 1.2 After finding the curvature and determining which points get which pieces we break it down into smaller groups. What I mean by this is that when a piece has another piece of the same type next to it it gets put into another smaller group with that other piece. (for this we would actually use "piece0" or stuff like that). The reason for this is that we can construct the curved pieces first and put them around their respective "circles" (we could average out the position of the points or something to find an approximate center) then we can try to loop over the whole thing again in order to find ways to connect those curved pieces.

Option 2: We start by matching the initial position of the curve and the tracks. Then we compare the end of the current piece of the track with the next point and determine which piece would most help realign us to the point. So we have a vector pointing directly "forward" on our tracks, and we compare that vector to the difference in positions between the end of our tracks and the next point. If the angel between the two vectors is larger than 45 degrees we use a curved piece. This method allows us to stay on the path but may run into problems when trying to get on the line but constantly being bounced between curved pieces (we would want a straight line but the computer would get confused and try to oscillate between curved pieces in stead). Also another problem would be height, because it is only focusing on the next piece and itself, it would not know if there are overlaps.

Option 1.1 would analyze the whole thing in one big step then try to build the tracks from there.

Option 1.2 would analyze chunks of it, build chunks, then analyze again, etc.

Option 2 would analyze only the next point, build, then repeat.

Edited by PlatinumFishy
• 1

##### Share on other sites

That’s a very clever project !

May I suggest that you should build the track by extruding a cross section through a spline, but only create the « blocks » at rendering, through displacement for example or with proper bump maps.

Once you extrude your cross section, you can use an attribute called « curveu » (which takes value between 0 and 1, from start of your curve to end of your curve), to layout proper UV along the extrusion axis, and create your blocks by setting the right repetition of textures :-)

Of course, if is cheating a bit, but this is what we do anyway when we do CG : cheating reality, no ?

##### Share on other sites
Posted (edited)

That is a clever idea! I’m not too good at texturing and rendering so I didn’t think of it in that way. I also have two other concerns with that:

The first Is that we would actually have to create a proper path. Honestly I have attempted (and succeeded) making a smooth path before when making a pulley system and it is a B. I would personally rather just use the resample the calculate a few key positions and then copy the pieces.

My second reason against that is if the user wanted to do sims with it. Whenever these wooden tracks are being used, there is usually a child causing havoc nearby.

Edited by PlatinumFishy

##### Share on other sites

You mean using the points from the resample to instance the blocks ? But if the curvature is wrong, The pieces / blocks won’t align properly, no ? But I understand your concern : indeed, if you want to make RBD, you need blocks that are independant (maybe you can cut them using curveu and a boolean operator and a foreach loop ?)

In 3DS Max I remember there was a way to make an object « follow » a path : the object would be « deformed » along that path. I think there is way to do that in Houdini, but don’t remember how : that would be neat, because you can prepare a straight version of your railway, by just copying-translating the same piece, and then feeding this whole rail to follow the path. Maybe that’s what you had in mind ? I may have misunderstood :-)

In any case, please post you work in progress from time to time, that’s interesting !

##### Share on other sites
Posted (edited)

Guys, that may interest you if you want to prepare a straight railway made of independent pieces (for RBD and so on), and then just feed that to a path deformer that will curve your geo without the headeache of making sure curvature is constant and so on (like it would be the case of a kid having standard pieces to prepare his railway in his bedroom :-)).

Edited by StepbyStepVFX

##### Share on other sites
Posted (edited)

Alright boys here is v1.0. It is fairly undocumented and kinda confusing but it's here. I /may/ clean it up later. Also I decided to go with method number 2.

EDIT: Doing this made me wish that Houdini had a do while node system. (I know they have it within VOPs but why cant we have it at SOP level)

trainstuff 1.1.hiplc

Edited by PlatinumFishy
• 1

##### Share on other sites

here's my take...

##### Share on other sites

Wouah this is very good thank you very much for your help. I will open your files and try to understand each technics

## Create an account

Register a new account