Mesh libraries: Using the 'mesh-asset' tag

TrainzDev

New member
The 'mesh-asset' tag provides a very useful function - the ability to make one asset load a mesh file from a different asset.

Consider a set of houses to represent a housing estate. You will often find a number of very similar but subtly different houses grouped together. Making these in the traditional style (with each house having a different mesh and texture stored within it) can result in a scene that renders rather slowly. The alternative of using the same house (with no variation) repeatedly is a lot faster, but can look very artificial.

If you can arrange for the different meshes to use the same texture without significantly increasing either the size of the texture or the polygon count of the mesh, you can have your cake and eat it - keep the subtle variation between the different assets, but have the faster rendering too.

Set this up by exporting all the different meshes into a single asset (generally a 'kind mesh'), and make all the houses ('kind scenery') with a mesh table which reads something like:

Code:
mesh-table
{
  default
  {
    mesh       suburban-house-01.im
    mesh-asset <kuid2:447264:12345:1>
  }
}

The house assets only need their config file and DLS screenshot in them. They do not need a copy of the mesh or the texture. When the house asset is loaded, Trainz will load suburban-house-01.im from <kuid2:447264:12345:1> instead of from the current asset. Each mesh loaded from <kuid2:447264:12345:1> is a candidate for mesh stitching - so if all the houses use the same single texture file, you can place all the different houses together in a scene and they will all be stitched together into the same buffer. (If there is multiple textures, one buffer is used per texture). A reduction in the number of buffers used in a scene will result in a significant performance improvement in Trainz. An example of this (using cars rather than houses) is documented in detail in the HowTo section of the TrainzDev Wiki.


Another way that 'mesh-asset' can be used is to re-use the same mesh multiple times in assets with different kinds. Consider a road vehicle. You might want one version as a scenery asset to place in surveyor, another version that can be used as automated road traffic (and thus needs to be 'kind trackside'), and a third version as part of a product to load onto car carrying rail wagons. Using the 'mesh-asset' tag, you can make all these assets use the same copy of the mesh file.

It is important to note that you can reference any mesh based asset in a 'mesh-asset' tag. The convention if you are making a mesh library yourself is to use 'kind mesh', but there is no requirement to do so. You can load a mesh from any asset kind that might reasonably be expected to contain a mesh. That's approximately anything that inherits from the MeshObject class.

Note that 'mesh-asset' isn't a replacement for 'alias'. It is not a method of reskinning - the texture file will always be loaded from the referenced asset along with the mesh. It does, however, allow you to pick and choose which meshes are loaded, and control how they are attached to your model using your local mesh table.
 
Is this a good summary?:

Alias
is the use of multiple textures (as multiple assets) on one mesh.
Mesh-asset is the use of a single mesh (as multiple assets) for one texture

Is there a modern equivalent of alias? It looks a lot more useful.
 
Last edited:
Yes and no-

* "alias" gives the ability to load a mesh, then swap the normal textures out for a substitute. This has obvious advantages in that you can reskin somebody else's model without having to redistribute their mesh (which would be illegal unless you had explicit permission to do so.) It has the downsides of making your asset "fragile"- changes to the parent asset will often break the derived asset. More importantly, it is not well supported by the Trainz game engine and the resulting performance is very poor (stationary frame rate won't be impacted, but loading will take longer and it may introduce visible pauses.)

* "mesh-asset" gives the ability to load a mesh which actually resides in another asset. This may be used to implement texture sharing, which can be a very big performance win if used appropriately. This technique is substantially less "fragile" than aliasing, since the mesh would need to be removed or reworked substantially in order to break any derived assets.

Of the two, the latter is more useful because it can be used to improve performance. While the former would seem like a useful trick, in practice it only degrades performance.

hth,

chris
 
Back
Top