Rail3D*

   

 

Getting Started With Strips


 


Strips are a bit daunting if you are used to the Fill panel syntax of Rail3D, but they are worth the effort: they give stock designers all sorts of new possibilities for creating complex shapes, and produce a result that not only looks better than the traditional solution in most cases, it also renders faster.

 

Basics

A strip definition starts with strip and ends with endstrip. If you forget endstrip, then Rail3D 2kD will try to read everything else in the file as part of the strip, and it will look very odd.

For each vertex in the strip, you need to define both the coordinates of the vertex itself and the direction of the normal to the surface at that point.

The normal to a surface at a given point is the line perpendicular to the surface and pointing outwards from the visible side of the surface. The direction is expressed as a vector, thus (0/0/1) is straight up, (0/−1/0) is backwards, etc. The length of the vector does not matter.

Normals are something we didn’t have to deal with explicitly in Rail3D before. DirectX uses them to decide how to light the panel. If the normal is pointing straight towards a light source, the panel should be bright; if the normal points away from the light it should be dark. For a Fill panel, the Rail3D program has to calculate the orientation of the panel in order to send the normals to DirectX.

For more details on normals and how they can be calculated, see moreaboutnormals.

 

Example

As an example, we can “translate” a Fill panel into a simnple strip with only four points.

 
 
Fill 134/75/25 134/75/125 134/1425/125 134/1405/25 217:30:25 -

This represents the lower part of the side of a coach, and is just a flat rectangle, with its sides parallel to the L and H axes. Thus the normal at each corner of this rectangle would be a line pointing out in the W direction, away from the side of the coach. We represent this as the vector (1/0/0).

 
 
STRIP  217:30:25 
134/75/25 1/0/0 
134/1405/25 1/0/0 
134/75/125 1/0/0 
134/1425/125 1/0/0 
ENDSTRIP

This should give exactly the same result as our Fill panel, but a little bit faster. Notice that the order of the vertices is different - we zig-zag across the shape, rather than going round the outside as we do with a Fill.

 

More Points

Now imagine we want to extend our carriage side a bit further upwards. With Fill panels, we would have to create a new panel with four points and a colour. With a Strip, we just add two further points to the existing strip definition:

 
 
STRIP  217:30:25 
134/75/25 1/0/0 
134/1405/25 1/0/0 
134/75/125 1/0/0 
134/1425/125 1/0/0 
124/75/225 1/0/0 
124/1425/225 1/0/0 
ENDSTRIP

This makes the advantage of the Strip clear - two Fill panels need eight vertices, and Rail3D has to calculate everything twice for the common points; the Strip only needs six vertices.

We can see that the carriage wall is sloping inwards between H=125 and 225, so we should probably adjust the normals a bit, to make sure that the part that tilts up towards the light is brighter than the vertical part. It isn’t necessary to be very precise about this - we can just guess some values and see if they look sensible.

Here we see that the wall slopes in by about 1 part in 10, so we could make the vector have W and H components in the same proportions. At the bottom of the sloping section, we can make it a bit less, to gve the smooth transition to the vertical part.

 
 
STRIP  217:30:25 
134/75/25 1/0/0 
134/1405/25 1/0/0 
134/75/125 20/0/1 
134/1425/125 20/0/1 
124/75/225 10/0/1 
124/1425/225 10/0/1 
ENDSTRIP

 

Adding a texture

Now, we can detail the strip by applying a texture. As a very simple example, imagine that we have a texture called “My_carriage.bmp” that corresponds exactly with our carriage side, so that we want to map the bottom left-hand corner onto the bottom left-hand corner of the panel, and so on.

We identify the point in the texture that corresponds to each vertex in the Strip using so-called U,V coordinates. This is a simple system in which we consider each side of the texture as running from 0 to 1, the bottom left-hand corner being (0,0). The advantage is that the coordinates stay the same even if we change the pixel size of the texture.

We can start by filling in the coordinates for the four corners:

 
STRIP  217:30:25  "My_carriage.bmp" 
134/75/25 1/0/0 @0,0
134/1405/25 1/0/0 @1,0
134/75/125 20/0/1 @...
134/1425/125 20/0/1 @...
124/75/225 10/0/1 @0,1
124/1425/225 10/0/1 @1,1
ENDSTRIP

We are left with the two points in the middle. Here we can work out the U,V coordinates in two ways:

  • one is to use the features in the bitmap to identify a point that corresponds to this vertex and transform the pixel values to U,V;
  • the other is to interpolate between the U,V values you already have. In this case this is easy - 125 is exactly halfway between 25 and 225, so we know that V=0.5 for these two points.
 
 
STRIP  217:30:25  "My_carriage.bmp" 
134/75/25 1/0/0 @0,0
134/1405/25 1/0/0 @1,0
134/75/125 20/0/1 @0,0.5
134/1425/125 20/0/1 @1,0.5
124/75/225 10/0/1 @0,1
124/1425/225 10/0/1 @1,1
ENDSTRIP

 

 


MRG 13/12/2013 14:26:42