Livery over MP

From FlightGear wiki
Revision as of 18:33, 8 March 2011 by BotFlightGear (talk | contribs) (Robot: Cosmetic changes)
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>
    <texture>Liveries/KLM.png</texture>
   </livery>
  </model>
 </sim>
</PropertyList>

In the example above, the texture files are also stored in the Models/Liveries/ directory of the aircraft.

Models/....xml

The first part is related to the nasal script. ("Aircraft/DR400/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/DR400/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>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 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 approperiate livery.

<file type="string">ANA</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 (eg. seperate files for wings and fuselage). Every texture needs it own property. You can add as many textures as you like.

Nasal/liveries.nas

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">All Nippon Airways</name>
    <texture>ANA-Livery.png</texture>
    <lights>ANA-Lights.rgb</lights>
   </livery>
  </model>
 </sim>
</PropertyList>

Remember the names (<texture> and <lights>), as you will need them in the model file in the next step.

Models/....xml

   <animation>
       <type>material</type>
       <object-name>wipers</object-name>
       <property-base>sim/model/livery</property-base>
       <texture-prop>texture</texture-prop>
       <texture>ANA-Livery.rgb</texture>
   </animation>

   <animation>
       <type>material</type>
       <object-name>lightedfin_0</object-name>
       <property-base>sim/model/livery</property-base>
       <texture-prop>lights</texture-prop>
       <texture>ANA-Lights.rgb</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".

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.