Rail3D*

   

 

Colour And Texture Remapping Tool



Older Rail3D models made with Fill panels are mostly based on colours, rather than textures. Where textures are used, they tend to be confined to small areas of detail (logos, grilles, etc.).

It has become clear that using a lot of small textures is not efficient in terms of framerate. Ideally, a model should use a single composite skin texture, with the relevant areas being u,v-mapped onto panels as required.

If you want to convert one of your old models to the more efficient Vertex Buffer/Indexed Triangle format, (e.g. by going via a Building Rail3D Models In3D Canvas) this step is essential, as you can only have one texture per vertex buffer. The addditional problem with this format is that all faces must be textured: colours cannot be used.

Broadly speaking, there are two possible approaches to converting your model:

  1. Create a new skin texture from scratch and map it onto your model in a 3d editor, discarding all the existing colour and texture information;
  2. Make a small “colour swatch” texture, and map the swatches individually onto faces of the relevant colour.

The Colour and Texture Remapping Tool was created to help with the second of these techniques. It allows you to do a lot of the necessary colour reduction and remapping before you import your model into a 3d modelling program.

The Colour and Texture Remapping Tool

Download the tool here: Attach:R3DColourTool.zip (34kB, 05.06.2006)

  • The tool can work either on a complete (stk or stc) file or on text pasted directly into the edit box.
  • Pressing Analyse generates a report listing the colours and textures found in the model.
    • Colours are listed in order of the number of panels they appear in
    • In brackets after the colour you will see the nearest other colour found in the model, with an indication of how far the two are apart in rgb space (nb: this uses a simple Pythagorean calculation of distance, which is not necessarily a good indication of the perceptual difference between two colours).
  • If you have selected Open Texture Files then the tool tries to find the files corresponding to the texture names and open them with the default application for the relevant image file type. This is useful if you have set up an image editor like Paintshop Pro as the default application for bmp and tga — you will have all the raw material you need for a composite texture open in one psp session. If you have the Windows image viewer as defaul application, you will typically only see the last image in the list.

Changing colours

The main reason you need to replace one colour by another is that we used to use variations of colour to simulate shading effects in older versions of Rail3D. Since the shading is now handled by DirectX, we don’t need this any more, and it makes it more difficult to work with the model if it contains a large number of different colours. If you’re importing your model into 3DCanvas, you will probably just be using the colours as a way of tagging panels that should be textured together, so you will want to reduce the number of different colours in the model.

You could simply use global search and replace in the Rail3D Editor to swap colours around, but this gets tricky if you were not consistent about things like use of delimiters (e.g. 90.90.90 is different from 90:90:90 and 90 90 90). It’s also quite tricky to spot a single panel of a slightly different colour in the middle of a big file. The Colour and Texture Tool is also clever enough to distinguish between colour 90:90:90 and point 90:90:90 — something that caused mysterious errors in my models more than once in the past…

  • Enter the R,G,B values of the source and destination colours, make sure that “Source colour” and “New Colour” are selected, then press “Replace”
  • The tool replaces colours “intelligently”, i.e. it analyses the Fill and Strip panels and looks for the colour parameters without taking account of what flavour of delimiters you used.
  • Lines that have been changed are italicised, so that you can see quickly whether anything went wrong.

Remapping textures

  • In your original model, you might have a texture called “my_logo.bmp” mapped in its entirety onto an individual panel on each side of your locomotive. You now want to replace this by a skin texture, where the logo corresponds to (say) the bottom left quarter of the texture. Thus you want every panel that used to have a reference to “my_logo.bmp” to have u,v coordinates like @0,0 0,0.5 0.5,0.5 0.5,0 .
  • Enter the texture name “my_logo.bmp” in the “Source Texture” box, and select Source Texture. You don’t need to select Source Mapping unless the fills or strips in the original model are already U,V mapped.
  • Enter the U,V coordinates (bottom left and top right) of the textured area in your new skin texture in the “New Mapping” boxes, and select New Mapping

Recalculating mapping

  • If your original model used U,V mapped strips or fills, but you want to merge the texture you used previously with another, so that the coordinates of the mapped area have changed, enter the original mapping coordinates in the Source Mapping box, and select Source mapping as well as New Mapping.
  • The tool does a simple linear interpolation between the old and new mappings for each point.

Mapping colours to textures

  • This is basically the same idea as texture remapping: you want every panel that is currently yellow to be u,v-mapped to the yellow swatch on your composite texture.
  • My initial tests suggest that this technique doesn’t give very good results when you import the file into a 3d modeling tool. One problem is that instead of a colour swatch being mapped across the whole yellow region of your model, the whole swatch is mapped onto each panel. This means that each vertex in your model has a separate set of u,v, coordinates for every face it belongs to.


import