Howto:Animate models

From FlightGear wiki
Revision as of 18:48, 28 June 2010 by Gijs (talk | contribs)
Jump to navigation Jump to search

Conditions

Multiple animations can make use of a conditional.

  • equals: property value is equal to value/property.
  • greater-than: property value is larger than value/property.
  • greater-than-equals: property value is greater than or equal to value/property.
  • less-than: property value is smaller than value/property.
  • less-than-equals: property value is smaller than or equal to value/property.

The example below is true when n1 has a value greater than 25.

 <condition>
  <greater-than>
   <property>engines/engine[1]/n1</property>
   <value>25</value>
  </greater-than>
 </condition>

Then there are some special tags:

  • and:
  • not:
  • or:

In the example below, the condition is true when either n1 is greater than 25% or equal to 0%.

 <condition>
  <or>
   <greater-than>
    <property>engines/engine[1]/n1</property>
    <value>25</value>
   </greater-than>
   <equals>
    <property>engines/engine[1]/n1</property>
    <value>0</value>
   </equals>
  <or>
 </condition>

An example of implementation into an animation looks as follows:

<animation>
 <object-name>Object</object-name>
 <type>rotate</type>
 <property>suface-positions/left-aileron-pos-norm</property>
 <factor>25</factor>
 <condition>
  <greater-than>
   <property>suface-positions/left-aileron-pos-norm</property>
   <value>10</value>
  </greater-than>
 </condition>
 <center>
  <x-m>-1.50</x-m>
  <y-m> 1   </y-m>
  <z-m> 0.25</z-m>
 </center>
 <axis>
  <x>0</x>
  <y>1</y>
  <z>0</z>
 </axis>
</animation>

Types

Pick

1rightarrow.png See Howto: Make a clickable panel#Pick for the main article about this subject.

Range

To prevent objects -like instruments- being drawn when the aircraft is actually too far away for them to be seen anyway, a range animation is used.

<animation>
 <type>range</type>
 <min-m>0</min-m>
 <max-m>30</max-m>
</animation>
  • min-m: the shortest distance (in meters) from the object center at which it is visible.
  • max-m: the largest distance (in meters) from the object center at which it is visible.

You could also use the generic level of detail (LOD) properties, which can be set by the user through View > Adjust LOD rangers:

  • /sim/rendering/static-lod/bare distance at which only a rough exterior model is required.
  • /sim/rendering/static-lod/rough distance at which most should be visible.
  • /sim/rendering/static-lod/detailed distance at which all details should be visible.

The animation code will look like this:

<animation>
 <type>range</type>
 <min-m>0</min-m>
 <max-property>sim/rendering/static-lod/bare</max-property>
</animation>

You can have both ranges (max and min) bound to a property, or just one of them.

  • min-property:
  • max-property:

Rotate

One of the most important and frequently used animations of all. It rotates an object to an absolute position in degrees, as provided by the property-value.

<animation>
 <object-name>Object</object-name>
 <type>rotate</type>
 <property>suface-positions/left-aileron-pos-norm</property>
 <factor>25</factor>
 <center>
  <x-m>-1.50</x-m>
  <y-m> 1   </y-m>
  <z-m> 0.25</z-m>
 </center>
 <axis>
  <x>0</x>
  <y>1</y>
  <z>0</z>
 </axis>
</animation>
  • factor: is optional.

Select

This animation selects (or unselects) objects when certain conditions are true (or false). The example below shows the object when the n1 of engine[1] is higher than 25%.

<animation>
 <object-name>Object</object-name>
 <type>select</type>
 <condition>
  <greater-than>
   <property>engines/engine[0]/n1</property>
   <value>25</value>
  </greater-than>
 </condition>
</animation>

Spin

Very similar to rotate, but the property provides a value in revolutions per minute (RPM) rather than an absolute position in degrees, and offset cannot be used.

<animation>
 <object-name>Object</object-name>
 <type>spin</type>
 <property>engines/engine[0]/n1</property>
 <factor>25</factor>
 <center>
  <x-m>-1.50</x-m>
  <y-m> 1   </y-m>
  <z-m> 0.25</z-m>
 </center>
 <axis>
  <x>0</x>
  <y>1</y>
  <z>0</z>
 </axis>
</animation>
  • factor: is optional.

Textranslate

A very important animation for cockpits! This animation moves textures over a surface.

<animation>
 <type>textranslate</type>
 <object-name>Object</object-name>
 <property>autopilot/settings/target-speed-kt</property>
 <factor>0.001</factor>
 <step>100</step>
 <axis>
  <x>0</x>
  <y>1</y>
  <z>0</z>
 </axis>
</animation>
  • factor:
  • step:

property * factor * step = the amount of pixels that the texture should be translated. If your texture is 256 pixels, an textranslate of 0.1 will result in the texture moving with 26 pixels, into the direction specified by the axis settings.

Timed

Swtiches between objects at specified intervals. This example switches between a lights-on model and a lights-off model. Lights on are shown 0.2 seconds, while lights off are displayed for 0.8 seconds.

<animation>
 <type>timed</type>
 <object-name>BacklightOn</object-name>
 <object-name>BacklightOff</object-name>
 <use-personality type="bool">true</use-personality>
 <branch-duration-sec>0.8</branch-duration-sec>
 <branch-duration-sec>0.2</branch-duration-sec>
</animation>

Translate