Howto:Creating 3D instruments

From FlightGear wiki
Revision as of 14:22, 4 July 2007 by Ajmacleod (talk | contribs)
Jump to navigation Jump to search

Introduction: This tutorial describes the basic process of creating a 3d instrument for use in FlightGear. For now, we're assuming that you have created the actual 3d model to use and wish to include it in a cockpit and animate it. As an example, we will be animating the ITT gauge for the Fokker 50.

What you need: You will need; a text editor (even notepad will do, but one that does syntax highlighting might help you spot typos more easily; if you're on Windows, Notepad++ looks suitable.

You will also need your 3d modelling package, and of course a copy of FlightGear.

Creating the XML file: The first step is to create an XML file which will load the 3d model and animate it. There are no hard and fast rules about where these files should live or what they must be called, but we'll follow the fairly standard procedure of calling it itt.xml and placing it in the Models directory.

So, using your favourite text editor, create a file called itt.xml in the Aircraft/fokker50/Models directory (folder).

It should start like this (and please remember that case is ALWAYS important);

<?xml version="1.0"?>
<PropertyList>
</PropertyList>

Everything you will add to this file must go between the <PropertyList> tags.

Now, our file does nothing useful at this point. First of all, we want to tell FG to load the 3d model of our instrument. Add a section under <PropertyList> like this;

  <path>itt.ac</path>

This is obviously the name of the 3d model file we wish to load. The model in question looks like this:

Fokker51 ITT screenshot1.jpg


Adding an animation:

As you can see, the main item to animate is the temperature needle, and its name is "needle" (you can animate either ac3d "objects" or complete "groups"). We will want to use a "rotate" animation (for more details on available animation types, see "model-howto.html" which is provided with FG in the Docs directory.)

So, we add an <animation> section to our XML file.

 <animation>
   <type>rotate</type>
   <object-name>needle</object-name>

Now, we need to specify a property which will determine the amount of rotation required; in other words, the property that provides the ITT value at any one time. To find the name of this property, we need to start FlightGear in the usual manner with the correct aircraft (fokker50 in this case). Once FG has started, open the property browser (file/browse internal properties). You will see the top level of the property tree. Click on "engines" and you will see a list of engines; click on the first one (engine) and you will see a long list of properties and their current values.

Fokker50 prop browser screenshot1.jpg

Now, we have a slight problem at this stage; the fokker50 was created before JSBSim could model turboprops, and so the ITT property is not available right now. For the purposes of this tutorial though, we'll just use the exhaust temperature instead; the process is what's important.

So, the next line in our XML file will be specify the property to use;

<property>engines/engine/egt_degf</property>

Next we need to specify exactly how much that property moves the needle. There are several ways to do this, but we'll use a simple interpolation table since these are especially useful in more complicated situations. The ITT gauge is marked from 0 degC to 1200 degC; since we're having to use a value that's reported in degF for now, we'll just convert those two values. 0 degC is about 32 degF and 1200 degC is about 2192 degF. Two handy tips here; for Linux/unix users, the "units" program is truly invaluable; for everyone, google has a useful units converter; for example search for " 1200 degrees celsius in fahrenheit"

On to our table then.

 <interpolation>
   <entry><ind>32</ind><dep>0</dep></entry>
   <entry><ind>2192</ind><dep>230</dep></entry>
 </interpolation>

The <ind> entries are what's indicated on the gauge; the <dep> entries determine how many degrees the object will be rotated by. In this case I found that number by rotating the needle in AC3D from one end of the scale to the other and reading off the rotation value reported (see screenshot)

Fokker50 rotation value.jpg

Having configured the type of animation, the controlling property, and specified the effect of that property, we need to describe an axis and centre for the animation.

In this case, the centre is easy, because the needle centre is at the origin of the 3d model. If you wanted the rotation centre to be somewhere else, you could use your modelling app to obtain these values.

 <center>
   <x-m>0</x-m>
   <y-m>0</y-m>
   <z-m>0</z-m>
 </center>

The axis is also very simple in this case;

 <axis>
   <x>-1</x>
   <y>0</y>
   <z>0</z>
 </axis>

The negative sign on the x axis means that the rotation will be clockwise when viewed from the -x direction (i.e. looking "forwards")

That concludes the rotation animation and so (as always) we need to add a suitable closing tag;

</animation>