Howto:Animate models: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (Syntaxhighlighting)
m (Robot: Cosmetic changes)
Line 3: Line 3:
This document provides basic information for all kind of animations. For more complex animations, you are advised to check the available [[aircraft]] for examples.
This document provides basic information for all kind of animations. For more complex animations, you are advised to check the available [[aircraft]] for examples.


==A note about animation order==
== A note about animation order ==
{{stub}}
{{stub}}


Animations are executed by FlightGear in the order that they are read in the model's .xml file. Therefore, it is very important to pay attention to the order, especially when multiple animations are applied to the same object(s).
Animations are executed by FlightGear in the order that they are read in the model's .xml file. Therefore, it is very important to pay attention to the order, especially when multiple animations are applied to the same object(s).


==Special code parts==
== Special code parts ==
===Axis===
=== Axis ===
An axis part is required in every animation that involves a rotating or moving thing.
An axis part is required in every animation that involves a rotating or moving thing.


Line 37: Line 37:
</source>
</source>


===Center===
=== Center ===
Various animations ([[#Rotate|rotate]], [[#Spin|spin]]) move around a center point.
Various animations ([[#Rotate|rotate]], [[#Spin|spin]]) move around a center point.


Line 50: Line 50:
The axis are similar to the ones of the 3D model, so finding coordinates is easily done in 3D modeling software.
The axis are similar to the ones of the 3D model, so finding coordinates is easily done in 3D modeling software.


===Conditions===
=== Conditions ===
Multiple animations can make use of a conditional.
Multiple animations can make use of a conditional.


Line 118: Line 118:
</source>
</source>


===Interpolation===
=== Interpolation ===
For non-fixed factors, an interpolation "table" can be created.  
For non-fixed factors, an interpolation "table" can be created.  


Line 156: Line 156:
You can add as many entries as you need. Interpolation tables are often used for gear animations (eg. to open doors during gear-movements and close them again once the gear is either retracted or fully extended).
You can add as many entries as you need. Interpolation tables are often used for gear animations (eg. to open doors during gear-movements and close them again once the gear is either retracted or fully extended).


===Name===
=== Name ===
With a name animation, you can group multiple objects.  
With a name animation, you can group multiple objects.  


Line 174: Line 174:
</source>
</source>


===Object-name===
=== Object-name ===
These names are set in the 3D model. Each single object has a unique name; for easy identification it is advised to use descriptive names (LeftElevator, Rudder etc.). Animations are only applied to those objects that are mentioned in an object-name line (one object per line!). Animations lacking those, will be applied to the entire model.
These names are set in the 3D model. Each single object has a unique name; for easy identification it is advised to use descriptive names (LeftElevator, Rudder etc.). Animations are only applied to those objects that are mentioned in an object-name line (one object per line!). Animations lacking those, will be applied to the entire model.


==Animation types==
== Animation types ==
===Alpha-test===
=== Alpha-test ===
<source>
<source>
  <animation>
  <animation>
Line 187: Line 187:
</source>
</source>


===Billboard===
=== Billboard ===
This faces an object towards the viewer. Often used on 2D objects, like clouds, trees and lights.
This faces an object towards the viewer. Often used on 2D objects, like clouds, trees and lights.


Line 200: Line 200:
* '''spherical:'''
* '''spherical:'''


===Dist-scale===
=== Dist-scale ===
Used to scale an object, based on the distance to the viewer.
Used to scale an object, based on the distance to the viewer.


Line 224: Line 224:
</source>
</source>


===Enable-hot===
=== Enable-hot ===
Scenery objects are automatically defined as solid by FlightGear, meaning that an aircraft can taxi on them and/or crash when touching. For certain objects (groundmarkings, beacon light-beams etc.) this might be an unwanted feature. The solidness can be disabled with the following animation:
Scenery objects are automatically defined as solid by FlightGear, meaning that an aircraft can taxi on them and/or crash when touching. For certain objects (groundmarkings, beacon light-beams etc.) this might be an unwanted feature. The solidness can be disabled with the following animation:


Line 236: Line 236:
* '''enable-hot:''' can be either true or false. Remember that objects are automatically solid, so it should not be nesecarily to set this at all when wanting solidness.
* '''enable-hot:''' can be either true or false. Remember that objects are automatically solid, so it should not be nesecarily to set this at all when wanting solidness.


===Flash===
=== Flash ===
<source>
<source>
  <animation>
  <animation>
Line 260: Line 260:
</source>
</source>


*'''offset:'''
* '''offset:'''
*'''factor:'''
* '''factor:'''
*'''power:'''
* '''power:'''
*'''two-sides:'''
* '''two-sides:'''
*'''min:'''
* '''min:'''
*'''max:'''
* '''max:'''


===Interactions===
=== Interactions ===
<source>
<source>
  <animation>  
  <animation>  
Line 276: Line 276:
</source>
</source>


*'''interaction-type:''' can have the following values:
* '''interaction-type:''' can have the following values:
**'''carrier-catapult:'''
** '''carrier-catapult:'''
**'''carrier-wire:''' makes the object act as an arresting wire, as used on [[aircraft carrier]]s.
** '''carrier-wire:''' makes the object act as an arresting wire, as used on [[aircraft carrier]]s.


===Material===
=== Material ===
An animation type that can be used in various ways.
An animation type that can be used in various ways.


====Changing liveries====
==== Changing liveries ====
Used for the [[Livery over MP]] system.
Used for the [[Livery over MP]] system.


Line 296: Line 296:
</source>
</source>


====Illumination====
==== Illumination ====
{{Main article|Howto: Illuminate faces}}
{{Main article|Howto: Illuminate faces}}
<source>
<source>
Line 313: Line 313:
Emission colors are multiplied by the factor-prop value. 1 is maximum coclor intensity, while 0 is the minimum. Colors are calculated according to the [http://en.wikipedia.org/wiki/RGB_color_model RGB color model].
Emission colors are multiplied by the factor-prop value. 1 is maximum coclor intensity, while 0 is the minimum. Colors are calculated according to the [http://en.wikipedia.org/wiki/RGB_color_model RGB color model].


===Noshadow===
=== Noshadow ===
<source>
<source>
  <animation>
  <animation>
Line 321: Line 321:
</source>
</source>


===Pick===
=== Pick ===
{{Main article|Howto: Make a clickable panel#Pick}}
{{Main article|Howto: Make a clickable panel#Pick}}


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


Line 356: Line 356:
* '''max-property:'''
* '''max-property:'''


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


Line 380: Line 380:
* '''factor:''' is optional.
* '''factor:''' is optional.


===Scale===
=== Scale ===
A scale animation scales (resizes) an object. This can be either property-value dependant (first example) or a fixed scale (second example).
A scale animation scales (resizes) an object. This can be either property-value dependant (first example) or a fixed scale (second example).


Line 411: Line 411:
* x.offset: the scale factor.
* x.offset: the scale factor.


===Select===
=== 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%.
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%.


Line 427: Line 427:
</source>
</source>


===Shader===
=== Shader ===
<source>
<source>
  <animation>
  <animation>
Line 440: Line 440:
* '''texture:''' path to the texture used by the shader.
* '''texture:''' path to the texture used by the shader.


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


Line 464: Line 464:
* '''factor:''' is optional.
* '''factor:''' is optional.


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


Line 486: Line 486:
property * factor * step * texture width/height = 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.
property * factor * step * texture width/height = 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===
=== 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.
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.


Line 500: Line 500:
</source>
</source>


===Translate===
=== Translate ===
The same as [[#Textranslate|textranslate]], but this animation moves a whole object (so including fixed textures). The example below will move an object 5 meters in the y-direction.
The same as [[#Textranslate|textranslate]], but this animation moves a whole object (so including fixed textures). The example below will move an object 5 meters in the y-direction.



Revision as of 18:10, 8 March 2011

The real world is full of motion. To simulate this in FlightGear, models must be animated.

This document provides basic information for all kind of animations. For more complex animations, you are advised to check the available aircraft for examples.

A note about animation order

This article is a stub. You can help the wiki by expanding it.

Animations are executed by FlightGear in the order that they are read in the model's .xml file. Therefore, it is very important to pay attention to the order, especially when multiple animations are applied to the same object(s).

Special code parts

Axis

An axis part is required in every animation that involves a rotating or moving thing.

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

The axis are similar to the ones of the 3D model. There is a difference between rotation and translation:

  • In rotation animations, the axis part defines around what axis the object rotates. Negative/positive values make the difference between counterclockwise and clockwise rotations.
  • In translate animations, the part defines along what axis the object moves. If the x-axis is poiting backwards, an x-value of -1 will result in forward motion.

You could also define two points, between which FlightGear will calculate the correct axis. This makes the use of a <center> tag redundant! Such coordinates are extremely useful for animating control surfaces (rudder, elevators etc.).

  <axis>   
   <x1-m> 4.9</x1-m>
   <y1-m> 7.1</y1-m>
   <z1-m>-1.0</z1-m>
   <x2-m> 5.9</x2-m>
   <y2-m>11.2</y2-m>
   <z2-m>-0.5</z2-m>
  </axis>

Center

Various animations (rotate, spin) move around a center point.

  <center>
   <x-m>-1.50</x-m>
   <y-m> 1   </y-m>
   <z-m> 0.25</z-m>
  </center>

The axis are similar to the ones of the 3D model, so finding coordinates is easily done in 3D modeling software.

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>

Interpolation

For non-fixed factors, an interpolation "table" can be created.

  <interpolation>
   <entry>
    <ind> 0.0</ind>
    <dep> 0.0</dep>
   </entry>
   <entry>
    <ind> 0.667</ind>
    <dep> 0.0</dep>
   </entry>
   <entry>
    <ind> 1.0</ind>
    <dep> 0.5</dep>
   </entry>
  </interpolation>

The lines above represent the following table:

Input Output
0.0 0.0
0.667 0.0
1.0 0.5

You can add as many entries as you need. Interpolation tables are often used for gear animations (eg. to open doors during gear-movements and close them again once the gear is either retracted or fully extended).

Name

With a name animation, you can group multiple objects.

 <animation>
  <name>Collection1</name>
  <object-name>Object1</object-name>
  <object-name>Object2</object-name>
  <object-name>Object3</object-name>
 </animation>

The example above creates a "virtual object" with the name Collection1. In animation, we can animate this group of objects, by using:

 <object-name>Collection1</object-name>

Object-name

These names are set in the 3D model. Each single object has a unique name; for easy identification it is advised to use descriptive names (LeftElevator, Rudder etc.). Animations are only applied to those objects that are mentioned in an object-name line (one object per line!). Animations lacking those, will be applied to the entire model.

Animation types

Alpha-test

 <animation>
  <type>alpha-test</type>
  <object-name>Object</object-name>
  <alpha-factor>0.01</alpha-factor>
 </animation>

Billboard

This faces an object towards the viewer. Often used on 2D objects, like clouds, trees and lights.

 <animation>
  <type>billboard</type>
  <object-name>Object</object-name>
  <spherical type="bool">true</spherical>
 </animation>
  • spherical:

Dist-scale

Used to scale an object, based on the distance to the viewer.

 <animation>
  <type>dist-scale</type>
  <object-name>Object</object-name>
  <interpolation>
   <entry>
    <ind>0</ind>
    <dep>1</dep>
   </entry>
   <entry>
    <ind>300</ind>
    <dep>4</dep>
   </entry>
   <entry>
    <ind>1500</ind>
    <dep>8</dep>
   </entry>
  </interpolation>
 </animation>

Enable-hot

Scenery objects are automatically defined as solid by FlightGear, meaning that an aircraft can taxi on them and/or crash when touching. For certain objects (groundmarkings, beacon light-beams etc.) this might be an unwanted feature. The solidness can be disabled with the following animation:

 <animation>
  <object-name>Object</object-name>
  <enable-hot type="bool">false</enable-hot>
 </animation>
  • enable-hot: can be either true or false. Remember that objects are automatically solid, so it should not be nesecarily to set this at all when wanting solidness.

Flash

 <animation>
  <type>flash</type>
  <object-name>Object</object-name>
  <offset>0.0</offset>
  <factor>1.0</factor>
  <power>2</power>
  <two-sides type="bool">false</two-sides>
  <min>0.0</min>
  <max>1.0</max>
  <center>
   <x-m>0.0</x-m>
   <y-m>0.0</y-m>
   <z-m>0.0</z-m>
  </center>
  <axis>
   <x>0.0</x>
   <y>-1</y>
   <z>0.1</z>
  </axis>
 </animation>
  • offset:
  • factor:
  • power:
  • two-sides:
  • min:
  • max:

Interactions

 <animation> 
  <type>interaction</type> 
  <object-name>Object</object-name> 
  <interaction-type>carrier-wire</interaction-type> 
 </animation>
  • interaction-type: can have the following values:
    • carrier-catapult:
    • carrier-wire: makes the object act as an arresting wire, as used on aircraft carriers.

Material

An animation type that can be used in various ways.

Changing liveries

Used for the Livery over MP system.

 <animation> 
  <type>material</type> 
  <object-name>Object</object-name>
  <property-base>sim/model/livery</property-base> 
  <texture-prop>engine</texture-prop> 
  <texture>KLM.png</texture> 
 </animation>

Illumination

1rightarrow.png See Howto: Illuminate faces for the main article about this subject.

 <animation>
  <type>material</type>
  <object-name>Object</object-name>
  <emission>
   <red>1.0</red>
   <green>0.2</green>
   <blue>0.0</blue>
   <factor-prop>controls/lighting/panel-norm</factor-prop>
  </emission>
 </animation>

Emission colors are multiplied by the factor-prop value. 1 is maximum coclor intensity, while 0 is the minimum. Colors are calculated according to the RGB color model.

Noshadow

 <animation>
  <type>noshadow</type>
  <object-name>Object</object-name>
 </animation>

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.

Scale

A scale animation scales (resizes) an object. This can be either property-value dependant (first example) or a fixed scale (second example).

 <animation>
  <type>scale</type>
  <object-name>Object</object-name>
  <property>sim/time/sun-angle-rad</property>
  <x-min>1.0</x-min>
  <y-min>1.0</y-min>
  <z-min>1.0</z-min>
  <x-factor>1.4</x-factor>
  <y-factor>1.4</y-factor>
  <z-factor>2.0</z-factor>
 </animation>
  • ?-min: the mimimum scale factor for each axis. If the property value would result in a smaller factor than this setting, the scale animation will hold.
  • ?-factor: the scale factor for each axis (factor*property=scale factor).
 <animation>
  <type>scale</type>
  <x-offset>0.5</x-offset>
  <y-offset>0.5</y-offset>
  <z-offset>0.5</z-offset>
 </animation>
  • x.offset: the scale factor.

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>

Shader

 <animation>
  <type>shader</type>
  <shader>chrome</shader>
  <texture>chrome2.png</texture>
  <object-name>Object</object-name>
 </animation>
  • shader:
  • texture: path to the texture used by the shader.

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 * texture width/height = 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

The same as textranslate, but this animation moves a whole object (so including fixed textures). The example below will move an object 5 meters in the y-direction.

 <animation>
  <type>translate</type>
  <object-name>Object</object-name>
  <property>controls/seat/pilot/position-norm</property>
  <factor>5</factor>
  <axis>
   <x>0</x>
   <y>1</y>
   <z>0</z>
  </axis>
 </animation>