help with .x objects

Status
Not open for further replies.
Joined
9 Apr 2006
Messages
405
Location
London, UK
Hi,

I am trying to make a night route for the Ongar branch and have encountered some problems.

I tried to convert some station buildings from .csv to .x file format so that I have a play with the window illuminations. However the .x object has gaps in the textures and sometimes, wrong texture is applied. See below...



Can someone give me some advice please?

Thanks
 
Sponsor Post - registered members do not see these adverts; click here to register, or click here to log in
R

RailUK Forums

Dennis

Established Member
Joined
8 Aug 2005
Messages
2,676
Location
Trowbridge
There are a couple of points to be considered when converting .csv to .x format (assuming you are using the converter on Mackoys site);

> comments in the .csv file being converted are are not permitted.

> make sure all textures are present in the same directory as the object, both during and after conversion; use of parent or subdirectories is not permitted.

> .x format uses black as the default transparency colour and therefore must not appear in the texture (except where transparent regions are desired).
 

Dennis

Established Member
Joined
8 Aug 2005
Messages
2,676
Location
Trowbridge
Unfortunately, I understand that is is necessary to remove all comments from .csv files before converting them.

For a night route, although .x files have the benefit of being able to 'glow', it is not necessary to convert all objects. In many instances, just modifying the textures may be sufficient to give the desired effect - as with the tunnel lighting in the tutorial series.

The main reason so many of the objects in the Clarendon night route are in the form of .x files is that a lot of them were rebuilt using modified textures. A good example would be the platforms underneath the streetlights where the illumination was applied using Photoshop's lighting effects, .x format being used just to add a little bit of luminosity.

day version;
View attachment HsleFormC.bmp

night version;
View attachment HsleFormC_illuminated.BMP

In a scene like this,

night platform.JPG

Objects worth converting in this scene are the streetlights, passenger information display, the footbridge (as different sides can be illuminated independently) and possibly the platform surfaces and wall. You will need to consider the options available in .x format for illuminating the subjects as there are two separate processes which govern the brightness of the objects;

> specular reflectance - specify the light direction in the route file so that it is behind you and at a low angle. The specular reflectance commands in .x files can then be used to illuminate faces appearing directly in front of you (as if illuminated by the train lights). This is particularly useful for objects close to the track and which are quite reflective (signs, bridges, relay cabinets).

> emissive lighting - this is how much the object glows and is independent of the lighting direction specified in the route file. Use this not just for objects which genuinly 'glow in the dark' like streetlights but also where reflections from other light sources occur (the platform surface under streetlights being a good example).

When I converted Clarendon to the night scenario, it's probably true to say it underwent an almost total rebuild and took about half the time to do as making the route in the first place!
 

Simon_G

Member
Joined
19 Mar 2006
Messages
115
Does that mean i have to take out every comment made in the .csv file first?
No, just export them from the structure viewer: I've never had any trouble doing it this way. Oooh - just had a fiddle and it seems that comments can be added to .X files using the C++ comment marker:

Code:
xof 0303txt 0032

Header {
 1;
 0;
 1;
}
// This is a comment
Mesh {
 30;
 5.000000;0.000000;0.000000;,     // so is this
 5.000000;0.500000;0.000000;,
 5.000000;0.500000;25.000000;,
BTW, Dennis, when you use specular reflection to create the effect of headlamps, don't you have problems when the track curves and the light direction moves away from behind you?
 
Joined
9 Apr 2006
Messages
405
Location
London, UK
The .x object that I made was exported from structure viewer. I will try to export it again tomorrow without comments. (Will be tedius taking out all the comments)
 

Dennis

Established Member
Joined
8 Aug 2005
Messages
2,676
Location
Trowbridge
BTW, Dennis, when you use specular reflection to create the effect of headlamps, don't you have problems when the track curves and the light direction moves away from behind you?


Yes - it can be an issue if it is used as the primary means of illuminating an object although on a fairly linear route its not a problem, particularly as the power of the specular reflectance can be varied on each face to at least partially compensate for directional changes.

If you look at the objects in the Clarendon night route, the specular reflectance has been used sparingly, emissive lighting combined with modified textures being the normal means of 'illumination'.

re exporting objects from structure viewer - never tried that, having always used the csv2x converter which didn't seem to work correctly when I had comments present.
 

Simon_G

Member
Joined
19 Mar 2006
Messages
115
If you look at the objects in the Clarendon night route, the specular reflectance has been used sparingly, emissive lighting combined with modified textures being the normal means of 'illumination'.
Thanks - that's what I would have expected.

Kelvin, I cut out the code for the extension from your csv file and saved it as a separate object, to see if I could find out what's going wrong. I exported it as a text format .X file from the viewer and this is the result:

extension.jpg

Apart from black parts of the transparencies being transparent, the only other glitch is connected with the texturing of the cube you have used for the near part of the roof, where I believe you numbered the vertices incorrectly in the CSV file. There doesn't appear to be much wrong with this part of the model per se. It's only when it's combined with the rest of the file that trouble arises.

My guess is that you are exceeding some size limit in the number of mesh blocks and/or vertices that the structure viewer is able to convert correctly. Your model contains a very large number of both, because you seem to have started a new mesh builder for each face. Not only does this mean lots of mesh builders, but it prevents adjacent faces from sharing veritces and so multiplies those as well.

BTW - I tried moving the extension code to the start of the complete CSV file and re-exporting the .X file for the whole station. When I displayed it in the viewer, the errors had moved from the extension to the main station building, which tends to support my theory that the problem is the complexity of the model, not errors in the coding.
 

Dennis

Established Member
Joined
8 Aug 2005
Messages
2,676
Location
Trowbridge
errm..how do you export objects from structure viewer? Assuming I might need something a bit more up to date than what I currently have (v1.5.9)
 

Simon_G

Member
Joined
19 Mar 2006
Messages
115
My version is 2.0.1652.30169 The current one on Mackoy's site appears to be 2.0.1666.34338, but worryingly the screenshot on the download page doesn't show the export facility on the file menu. With luck, it's just an old image.
 
Joined
9 Apr 2006
Messages
405
Location
London, UK
Thanks for the tip Simon,

I managed to convert into .x by splitting the building into 2 .csv files. Is there a way to merge .x files together?

Regarding the transparancy issue, is there a way to stop black being transparant or to change the transparant colour? Its not very practicle if I cant convert objects with black bits into .x
 

Simon_G

Member
Joined
19 Mar 2006
Messages
115
Glad, it's working, Kelvin. In theory, I *think* you could just copy the Mesh{} block from one file into another, but I've never tried it and I could be wrong. In .X format as written by the Structure viewer, a Mesh block looks like

Code:
Mesh {

.... several inner blocks

 MeshTextureCoords {       <<--- this is always the last inner block

.... lots of coordinates

  }
}

Make sure you copy the 'Mesh' keyword and all the closing curly braces; when you paste it into the other file be careful not to mix it up with the block that's already there. I think you would be better off trying to simplify the CSV files by merging some of your meshbuilder sections together, but there's no harm in giving it a go.

You can get round the problem of black being transparent by editing the pallette of your texture. .X takes the first colour in the pallette (usually black) as transparent, so if you put some other colour in the first slot, that will be the transparent colour. I don't know what graphics program you use, but if it can't edit pallettes, I think IrfanView will do the job.
 
Joined
9 Apr 2006
Messages
405
Location
London, UK
Glad, it's working, Kelvin. In theory, I *think* you could just copy the Mesh{} block from one file into another, but I've never tried it and I could be wrong. In .X format as written by the Structure viewer, a Mesh block looks like

Code:
Mesh {

.... several inner blocks

 MeshTextureCoords {       <<--- this is always the last inner block

.... lots of coordinates

  }
}

Make sure you copy the 'Mesh' keyword and all the closing curly braces; when you paste it into the other file be careful not to mix it up with the block that's already there. I think you would be better off trying to simplify the CSV files by merging some of your meshbuilder sections together, but there's no harm in giving it a go.

You can get round the problem of black being transparent by editing the pallette of your texture. .X takes the first colour in the pallette (usually black) as transparent, so if you put some other colour in the first slot, that will be the transparent colour. I don't know what graphics program you use, but if it can't edit pallettes, I think IrfanView will do the job.

Unless I am doing somethng wromg, the copying and pasting bit doesnt work. I copied everything from Mesh{ to }} but the newly copied structure does not appear when viewed. I assume that there is an ending block somewhere in the existing code that stops further codes from being read thus the new codes are ignored.
 

Simon_G

Member
Joined
19 Mar 2006
Messages
115
Seems so - I just had a go and the second mesh block was ignored.

Edit: As far as I can see from this article: http://www.gamedev.net/reference/articles/article1196.asp having multiple mesh blocks isn't illegal (though I notice they are named in the article - I tried that and it doesn't work in the viewer), so this looks like a viewer thing. It may (or may not!) be the same in BVE4, but I haven't tried that yet!

I realised that the obvious way to combine .X files is in the structure viewer. Simply chop up the CSV file and export each piece as a .X file, then load the .X files you want to combine into the viewer and re-export. This seems to work for NW_Building.csv at any rate.

BTW - sorry to harp on about this but I do think your building objects could do with looking at. I've just noticed that you haven't included a 'GenerateNormals' statement in each of your Meshbuilder sections, which means that the illumination of the faces will not be correct. As far as I can see this also affects the exported .X version.
 
Joined
9 Apr 2006
Messages
405
Location
London, UK
BTW - sorry to harp on about this but I do think your building objects could do with looking at. I've just noticed that you haven't included a 'GenerateNormals' statement in each of your Meshbuilder sections, which means that the illumination of the faces will not be correct. As far as I can see this also affects the exported .X version.

Sorry Simon for the delayed response- I didnt realise that you have edited your post to include this.

When I first coded the file, I left out the generatenormals statement by mistake. But somehow, the colour shade of the bricks and roof seemed OK, so therefore I continued building other faces without generatenormals (I copied and pasted the statements).

Upon route completion, I have tried to reinstate the generatenormals but the building appeared too bright so therefore I kepted the old file.

The windows of the buildings are of a separate bitmap, so I can use generatenormals on the statements regarding windows.

BTW, today is the 12th anniversary of the last ever Ongar train!
 

Derek Kaye

Member
Joined
9 Jun 2005
Messages
188
Location
Loughborough
There is a nice cheat for darkening faces without changing the bitmaps. add SetColor 100,100,100 to the end of the GenerateNormals section (i.e. after the texture coordinates. Play about with the RGB values until you get what you want.
 

Simon_G

Member
Joined
19 Mar 2006
Messages
115
Upon route completion, I have tried to reinstate the generatenormals but the building appeared too bright so therefore I kepted the old file.
If you leave out GenerateNormals, you don't get shading due to the direction of lighting and your object will appear flat. If you still have the modified object, compare it with the original in the Structure Viewer - try rotating it to see how the brightness of the faces changes. As Derek says, if an object looks too bright when correctly shaded, there are other ways of adjusting it.
 
Status
Not open for further replies.

Top