Livery over MP

From FlightGear wiki
(Redirected from Livery selection dialog)
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:

Where aircraft is the name of the aircraft.

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. For example, if you have made a KLM livery, then you need to make a file called KLM.xml in the 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 base of the property tree (/), and on all remote machines on the MP network it's one of the multiplayer branches in /ai/models/multiplayer[n]. 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" encoding="UTF-8"?>
 
<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; the texture path is relative to the model's xml in which it is used.

Models/model.xml

The first part is related to the nasal script. aircraft.livery_update.new("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.

In order to enable livery changes also for MP (Multi-Player) use, add the following code to your model.xml file:

<?xml version="1.0" encoding="UTF-8"?>
 
<PropertyList>

<nasal>
  <load>
    <!--
      ##############################################################################
      # The on-load Nasal is not executed when this file is loaded as the user
      # aircraft. The code is only executed if the file is loaded for a remote
      # aircraft in Multi-Player mode (MP)
      ##############################################################################
    -->
    <![CDATA[
      var livery_update = aircraft.livery_update.new("Aircraft/747/Models/Liveries");
    ]]>
    </load>
  
  <unload><![CDATA[
    livery_update.stop();
  ]]></unload>
</nasal>

<!-- ... -->

</PropertyList>

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.

Caution  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");

aircraft-set.xml

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

<sim>

<!-- ... -->

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

<!-- ... -->

</sim>

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:

<sim>

<!-- ... -->

  <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>

<!-- ... -->

</sim>

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" encoding="UTF-8"?>
 
<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.

aircraft-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 Ctrl+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 Ctrl+p.

Depending on your model and their object origins, the model can be a mess afterwards. To fix this, you have to reset your objects' origin, having them at a 0 offset in relation to the parent.

  • Use Shift+c to reset the cursor to scene origin (0,0,0).
  • Next, 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 re-parent them).

Do not parent glass and/or other transparent objects to the main parent. Also, if using different effects on different objects, those with a 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 while switching the views. Also see the F-14B as a very good example!

Testing

To ensure that your livery setup works correctly over MP, you can start two instances of FlightGear locally. See Howto:Multiplayer § Local setup for testing for details

Sharing your liveries

Of course 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 Liverieslargest FG repository with (almost) all available liveries, based on real aircraft
  • UnitedFreeWorldrepository with lots of liveries (and scenery/aircraft), both realistic and fictional

Related content

Wiki articles

Source code