Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

User:Toryx/Sandbox

From FlightGear wiki
Jump to: navigation, 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.

Getting started

Adding livery support to your aircraft is quite easy but contains some annoying pitfalls you could encounter if you forget/oversee some of the hints listed here. In general, you have to follow 3 steps:

  1. Preparing the liveries
  2. Create, include and enable the nasal script
  3. Define which of the elements of your aircraft shall get a livery

Please make sure you follow each step carefully. FG is especially picky with paths: While the path to the .ac-files inside your .xml-files is based on flightgears root directory (e.g. “Aircraft/A310/Models/fuselage.xml”), the texture path is relative to the model's xml in which it is used.

Naming convention

The utilization of placeholdes like “...” or “<>” in filenames can be very confusing. To avoid this, we´ll use the Boeing 747 as an example to name alle the folders and files in this wiki. So if we talk about the Aircraft/747/747-set.xml file but you´re working on the A310-204, you should edit the Aircraft/A310/A310-204-set.xml.

I think you got the point.

For the liveries, it´s always a good idea to include the airline name and the decade this livery was used into the filename. In this example, we used the KLM livery of the 1990s and call it KLM90 For further details on naming conventions, xml-files and paths, consult the wiki:Howto:Make_an_aircraft.

Files to edit

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

  • Aircraft/747/747-set.xml
  • Aircraft/747/Models/747.xml
  • Aircraft/747/Models/Liveries/*.xml (one file for each livery you´d like to use)
  • Nasal/liveries.nas

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


Instructions

Preparing your liveries

The Howto:Edit a livery is a perfect start. Just mind one thing: Be careful with transparency. It can cause a lot of lag or simply confuse the renderer. Under some conditions, even a single pixel with hardly visible transparency can cause problems with the render engine. To avoid this, either delete the alpha-channel or just place a filled layer (white/whatever) in the background of your layer. In your source-files, each layer can contain transparency as long as the background is filled.

As a result, you should get a .png or another image file. Place it in your livery directory (in our example: Aircraft/747/Models/Liveries). To tell FG to use this file, we also need a .xml.

Let's say we got a KLM livery for our Boeing 747, we then need to make a file called KLM90.xml in our Models/Liveries directory.
Background information: 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/KLM90.png</747-texture>
    </livery>
   </model>
  </sim>
 </PropertyList>

Please note the <747-texture>Liveries/KLM.png</747-texture> property. The name “747-texture” of this property is free, just make sure you use exactly the same name later. Most of the model-designers simply call this property “texture”. Please also note the relative path in this property! The texture path is relative to the model's xml in which it is used.


Create, include and enable the nasal script

Menu-based livery selection depends on a small nasal script. To create and enable it, edit the following files.


Aircraft/747/Nasal/liveries.nas
As a first step you need to create the nasal-file. Just change the directory to the correct settings. 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/747/Models/Liveries");


Aircraft/747/747-set.xml
The second step is telling FlightGear to make use of the nasal-file you just created. Edit your models -set.xml (In our example: Aircraft/747/747-set.xml) and add this section to the end of the file (but before </PropertyList>!)

 <nasal>
  <B747> 
   <file>Nasal/liveries.nas</file>
  </B747>
 </nasal>

The naming of the <B747> tag is more or less freeform, but using the aircraft's name is probably a good idea.
The following part is really important. If this sction is not included, the livery changes will not be visible over MP!

 <model>
  <path>Aircraft/747/models/KLM90.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 Aircraft/747/Models/Liveries/KLM90.xml file name of the appropriate livery.

 <file type="string">KLM90</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>


Aircraft/747/Models/747.xml
The third 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>


Define which of the elements of your aircraft shall get a livery

This 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/KLM90.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!


Aircraft/747/Models/Liveries/KLM90.xml

 <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/KLM90.png</texture>
 </animation>

Please note the <texture-prop>747-texture</texture-prop> element. This is the place to define the name of the property we used in Preparing your liveries at the beginning of this text. If you prefered to use <texture> instead of <747-texture> there, you need to write <texture-prop>texture</texture-prop> to your Aircraft/747/Models/Liveries/KLM90.xml.



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

Also prevent transparency where possible- it will prevent lags during switching the views. See also the f14b as a 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

Common mistakes

  • If you can not see the menu, you probably did not add the menu-section to the -set.xml (e.g. Aircraft/747/747-set.xml)file.
  • If you see the menu but clicking the menu-item does not give any reaction, check if you added the .nas file and added the <nasal> section to your root .xml (e.g. Aircraft/747/Models/747.xml).
  • If you see the livery selection box but clicking a livery does not show any reaction, check this:

The xml-parser of FG does not like recursively declared tags like <model><model>...</model></model>.
Example:Aircraft/Models/A310-308.xml (the root model file):

<PropertyList>

....

<model>
 <name>Fuselage</name>
 <path>Aircraft/A310/Models/Fuselage.xml</path>
 <offsets>
  <x-m> 0.0</x-m>
  <y-m> 0.0</y-m>
  <z-m> -0.35</z-m>
 </offsets>
</model>

....

</PropertyList>

Aircraft/Models/Fuselage.xml:

<PropertyList>

....

<model>
 <path>Fuselage.ac</path> 

 <animation>
  <type>material</type>
  <object-name>fuselage</object-name>
  <property-base>sim/model/livery</property-base>
  <texture-prop>texture</texture-prop>
  <texture>Liveries/HF90.png</texture>
 </animation>
</model>

...

</PropertyList>

This does not work because both files declare a <model> section inside each other. Removing the <model>-tag from fuselage.xml should help.

  • If the aircraft shows a funny colored (green/orange) texture instead of the expected livery, you might have problems with the transparency or alpha-channel of the texture file. Try removing the transparency.

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