Livery over MP: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (menu entries should always open() the dialog (not toggle it))
m (comments about the (non-)structure of an XML overlay file)
Line 13: Line 13:


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


  <?xml version="1.0"?><nowiki>
  <?xml version="1.0"?><nowiki>
Line 64: Line 64:


===liveries.nas===
===liveries.nas===
The only thing you might change in the nasal file is the directory of the liveries.
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 <tt>sim/model/livery/name</tt>, then you have to add this as second function argument.


  aircraft.livery.init("Aircraft/DR400/Models/Liveries");
  aircraft.livery.init("Aircraft/DR400/Models/Liveries");
Line 72: Line 72:
   <path>Aircraft/DR400/models/dr400.xml</path>
   <path>Aircraft/DR400/models/dr400.xml</path>
   <livery>
   <livery>
   <file type="string">default</file>
   <file type="string"/>
   </livery>
   </livery>
  </model>
  </model>

Revision as of 07:49, 20 October 2008

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 a plane in FlightGear. To get new liveries into FlightGear CVS, you need to have them availabe with this script.

The examples are based on the Robin DR400.

Files

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

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

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

Models/Liveries

For every livery we need to make a file. Let's say we got a Rescue livery, we then need to make a file called Rescue.xml in our Models/Liveries directory. When a particular livery gets 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">Default</name>
    <texture>texture.rgb</texture>
   </livery>
  </model>
 </sim>
</PropertyList>

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

<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 software like Blender or AC3D. The <texture>S76livery.rgb</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>LHgeardoor</object-name>
  <object-name>RHgeardoor</object-name>
  <object-name>S76C</object-name>
  <object-name>RF.door</object-name>
  <object-name>LF.door</object-name>
  <object-name>Rr.Door</object-name>
  <object-name>Lr.Door</object-name>
  <object-name>RHbaggage</object-name>
  <object-name>LHbaggage</object-name>
  <object-name>RHfrtgeardoor</object-name>
  <object-name>LHfrtgeardoor</object-name>
  <property-base>sim/model/livery</property-base>
  <texture-prop>texture</texture-prop>
  <texture>texture.rgb</texture>
</animation>

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/DR400/Models/Liveries");

s76c-set.xml

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

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>Robin DR 400</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>

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