Livery over MP

From FlightGear wiki
Revision as of 15:12, 17 August 2014 by HHS (talk | contribs) (updating my lines - many thanks to i4dnf)
Jump to navigation Jump to search
The livery selection dialog of the Sikorsky S76C.

On this page we describe how you make use of a script to get a livery selection dialog for an aircraft or vehicle in FlightGear. To get new liveries, you need to have them available with this script.

If you want to add a new livery to a plane that already makes use of the livery select system, you'll only have to follow the steps under Models/Liveries.

A note to those who wish to make a livery

If your livery is likely to be edited by other users, consider making a paintkit in addition to your livery.

A paintkit is where you create a blank livery which shows only constructional elements like bolts, rivets, windows, doors and panels. This is done so any other users looking to create their own livery can make a realistic looking livery with these construction elements, without having to redraw them or trying to avoid painting over them. This makes the process of creating a livery a more fun and less stressful task.

Paintkits are usually provided within the aircraft's Models/ directory and/or at the livery database.

Files to edit

There are a few files we need to make (or edit), namely:

  • ...-set.xml
  • Models/....xml
  • Nasal/liveries.nas

We also have to make a new directory to store our liveries in. Let's make it Aircraft/.../Models/Liveries.

Models/Liveries

For every livery we need to make a file. Let's say we got a KLM livery, we then need to make a file called KLM.xml in our Models/Liveries directory. When a particular livery is selected, its XML file is copied to the aircraft's property tree. On the pilot's side this is the main property tree /, and on all remote machines on the MP network it's one of the multiplayer branches in /ai/models/multiplayer[]. The structure of livery XML files is completely free. There just has to be a property containing a name for the selection dialog, and aircraft.livery.init() must be told which it is. By default it is sim/model/livery/name.

 <?xml version="1.0"?>
 
 <PropertyList>
  <sim>
   <model>
    <livery>
     <name type="string">KLM Royal Dutch Airlines</name>
     <747-texture>Liveries/KLM.png</747-texture>
    </livery>
   </model>
  </sim>
 </PropertyList>

In the example above, the texture files are also stored in the Models/Liveries/ directory of the aircraft; the texture path is relative to the model's xml in which it is used.

Models/....xml

The first part is related to the nasal script. ("Aircraft/747/Models/Liveries"); points FlightGear to the directory where we store our liveries. This is a different directory for every plane, but there should be only one folder for one plane, containing all the liveries for that plane. Add the following code to your models .xml file:

 <nasal>
  <load>
   var livery_update = aircraft.livery_update.new("Aircraft/747/Models/Liveries");
  </load>
  
  <unload>
   livery_update.stop();
  </unload>
 </nasal>

The second part is very important and probably the hardest of all. We need to set which parts of the model should change when you select a new livery. To find the object-names, you could make use of 3D modelling software like Blender or AC3D. The <texture>Liveries/KLM.png</texture> part points FlightGear to the livery that should be shown on startup.

Warning: be sure you don't have a slash (/) in front of sim/model/livery in the <property-base> tag! Otherwise, all planes will get the same livery!

 <animation>
  <type>material</type>
   <object-name>Fuselage</object-name>
   <object-name>Hstab</object-name>
   <object-name>Vstab</object-name>
   <property-base>sim/model/livery</property-base>
   <texture-prop>747-texture</texture-prop>
   <texture>Liveries/KLM.png</texture>
 </animation>

Nasal/liveries.nas

The only thing you might change in the nasal file is the directory of the liveries. If you don't have the livery name in sim/model/livery/name, then you have to add this as second function argument.

aircraft.livery.init("Aircraft/.../Models/Liveries");

...-set.xml

The follow part is really important. If this is not included, the livery changes will not be visible over MP!

 <model>
  <path>Aircraft/.../models/....xml</path>
  <livery>
   <file type="string"/>
  </livery>
 </model>

If you want the default livery to be something else than the first in the list, replace the file type part with the following, containing the Models/Liveries/....xml file name of the appropriate livery.

 <file type="string">KLM</file>

To make a nice button in the menubar we need to add the following code, just above the </sim> tag.

 <menubar>
  <default>
   <menu n="100">
    <label>...</label>
    <enabled type="bool">true</enabled>
    <item>
     <label>Select Livery</label>
     <binding>
      <command>nasal</command>
      <script>aircraft.livery.dialog.open()</script>
     </binding>
    </item>
   </menu>
  </default>
 </menubar>

Multiple texture files per livery

Some models use multiple textures file (e.g. separate files for fuselage and wings). Every texture needs it own property. You can add as many textures as you like.

Nasal/liveries.nas

This is the same as "ordinary" aircraft with just one texture. You will find the content of this file earlier in this article.

Models/Liveries

Instead of just one texture we have to deal with multiple ones now.

 <?xml version="1.0"?>
 
 <PropertyList>
  <sim>
   <model>
    <livery>
     <name type="string">KLM Royal Dutch Airlines</name>
     <texture-fuselage>KLM-Livery-fuselage.png</texture-fuselage>
     <texture-wings>KLM-Livery-wings.png</texture-wings>
    </livery>
   </model>
  </sim>
 </PropertyList>

Models/....xml

    <animation>
        <type>material</type>
        <object-name>hull</object-name>
        <object-name>nosecone</object-name>
        <property-base>sim/model/livery</property-base>
        <texture-prop>texture-fuselage</texture-prop>
        <texture>KLM-Livery-fuselage.png</texture>
    </animation>
 
    <animation>
        <type>material</type>
        <object-name>left-flap</object-name>
        <object-name>left-aileron</object-name>
        <property-base>sim/model/livery</property-base>
        <texture-prop>texture-wings</texture-prop>
        <texture>KLM-Livery-wings.png</texture>
    </animation>

Note that the texture-prop in both animations are different. They should match the tags around the textures in your Models/Liveries/ files.

...-set.xml

Is the same as "ordinary" aircraft with just one texture. You will find the content of this file earlier in this article.

Performance Improvements

For livery changing it seems to be important to parent all objects with the same texture. In Blender select all objects and press "ctr-p" to make it parent to the last selected. E.g.: fuselage and doors with the same texture: select at first the doors and then at last the fuselage and press "ctr-p".

Depending on your model and their object origins the model can be a mess afterwards. To fix it you have to reset your objects origin, having them a 0 offset to the parent. Use Shift + c to reset the cursor to scene origin (0,0,0). Then select the parent -> Object -> Transform -> Origin to 3d-cursor. Then with the parent still selected-> Shift + g -> Children (to select all children objects). Alt+p -> Clear parent and keep transform (to clear the "wrong" parent relationship), then keeping all the children selected Object -> Transform -> Origin to 3d Cursor. Then with the children still selected, shift select the parent, ctrl + p -> Object (to reparent them).

Do not parent glass and/or other transparent objects to the main parent. Also if using different effects on different objects, those with the different effect cannot be parented to the main parent (they will have their effect overwritten by the parent's)

Also prevent transparency where possible- it will prevent lags during switching the views. See also the f14b as an very good example!

Testing

To ensure that your livery setup works correctly over MP, start two instances of FlightGear locally, one with

fgfs --multiplay=out,10,localhost,5702 --multiplay=in,10,localhost,5701

and one with

fgfs --multiplay=out,10,localhost,5701 --multiplay=in,10,localhost,5702

Sharing your liveries

Ofcourse you want other people to use and enjoy your liveries as much as you do. Therefore, other users should be able to download them.

We have some FlightGear hosts, where you can upload your liveries to:

  • FlightGear Liveries largest FG repository with (almost) all available liveries, based on real aircraft.
  • UnitedFreeWorld repository with lots of liveries (and scenery/aircraft), both realistic and fictional.