Howto:3D Aircraft Models: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 92: Line 92:


==Animating the Model==
==Animating the Model==
Now for the interesting part. FlightGear allows you to animate models by having parts rotate or spin in response to property changes: for example, the propellers can spin when the engine is on and the elevators can move up and down with your controller. There is no fixed limit on what parts can be animated: the only requirements are that the part is named in the 3D model file, and that there is a property in the main tree that you can use to get the positioning information.
Now for the interesting part. FlightGear allows you to animate models by having parts rotate or spin in response to property changes: for example, the propellers can spin when the engine is on and the elevators can move up and down with your controller. There is no fixed limit on what parts can be animated: the only requirements are that the part is named in the 3D model file, and that there is a property in the main tree that you can use to get the positioning information.  When animating your model, it is very helpful to find an aircraft with parts similar to yours and use it as an example.  Cut and paste the code into your wrapper file and then edit to suit.  


Currently, there are three types of animation recognized:
Currently, there are four types of animation recognized:  


* none  
    * none  
* spin  
    * spin  
* rotate  
    * rotate
    * translate


In the future, many more will be added, but the last two are sufficient for animating the main control surfaces of many standard-configuration aircraft. none is a no-op; spin rotates the object around an axis with a known rotational velocity (not worrying about the exact position), and rotate rotates the object around an axis to an exact position.
These  are sufficient for animating the main control surfaces of many standard-configuration aircraft. none is a no-op; spin rotates the object around an axis with a known rotational velocity (not worrying about the exact position), rotate rotates the object around an axis to an exact position and translate moves an object along an axis.  


Every animation appears inside an animation element, and contains a type property and at least one object-name property:
Every animation appears inside an animation element, and contains a type property and at least one object-name property:
Line 176: Line 177:
In this example, the gear position (from 0.0 for fully retracted to 1.0 for fully extended) is multiplied by a factor of 120 and an offset of -1, then clamped to between -90 and 0. In the 3D model, the gear is extended by default, so we end up with the following rotations through the gear's range of movement:
In this example, the gear position (from 0.0 for fully retracted to 1.0 for fully extended) is multiplied by a factor of 120 and an offset of -1, then clamped to between -90 and 0. In the 3D model, the gear is extended by default, so we end up with the following rotations through the gear's range of movement:


TODO
The gear does not move at all during the first 1/4 of the position-norm value, giving the doors a chance to open and close in a separate animation. Obviously, this would be easier to manage with an interpolation table (see farther below).
 
The gear does not move at all during the first 1/4 of the position-norm value, giving the doors a chance to open and close in a separate animation. Obviously, this would be easier to manage with an interpolation table, and future versions of the model animation will likely support interpolation.


For a spin animation, the property provides a value in revolutions per minute (RPM) rather than an absolute position in degrees, and offset is not used. You can still use factor to scale the property value if it is not in RPM.
For a spin animation, the property provides a value in revolutions per minute (RPM) rather than an absolute position in degrees, and offset is not used. You can still use factor to scale the property value if it is not in RPM.
Line 283: Line 282:
  </nowiki>
  </nowiki>


You can get a lot of your initial measurements by viewing the model in a 3D editor like PPE, and you can also use PPE to name or rename objects so that you can animate them in FlightGear. In the end, though, you'll almost have to do a little tweaking by trial and error until everything looks right.
You can get a lot of your initial measurements and name or rename objects by viewing the model in a 3D editor like Blender or AC3D, so they can be animated in FlightGear. In the end, you'll most likely have to do a little tweaking by trial and error until everything looks right.
 
 
There is also a second method to do this animation you may find easier.
 
Code:
 
<axis> 
  <x1-m>  8.02</x1-m>
  <y1-m> 14.38</y1-m>
  <z1-m> -0.34</z1-m>
  <x2-m> 11.85</x2-m>
  <y2-m> 20.58</y2-m>
  <z2-m>  0.36</z2-m>
</axis>
 
Using this method you select the two ends of the axis where x1, y1 and z1 are the locations of one end of the object, while x2, y2 and z2 are for the other end.  So for a rudder, you would use the upper point and lower point where the rudder is connected to the vertical stabilizer. Then the object will rotate between those two points.  The center tags can and should be removed, as they are no longer needed.  Rather than using the center of the object and then picking the axis it rotates around, you instead define the two ends of the axis.
 
Here's a complete example, showing the animation for the rudder on the Airbus A320.  Also note that interpolation is used to replace the factor and min/max properties: 
 
<animation>
  <type>rotate</type>
  <object-name>Rudder.L</object-name>
  <object-name>Rudder.R</object-name>
  <property>surface-positions/rudder-pos-norm</property>
  <interpolation>
    <entry><ind>-1.0</ind><dep>-25.0</dep></entry>
    <entry><ind>0.0</ind><dep>0.0</dep></entry>
    <entry><ind>1.0</ind><dep>25.0</dep></entry>
  </interpolation>
  <axis> 
    <x1-m> 14.8887</x1-m>
    <y1-m> 0</y1-m>
    <z1-m> -0.306402</z1-m>
    <x2-m> 17.3891</x2-m>
    <y2-m> 0</y2-m>
    <z2-m> 5.5629</z2-m>
  </axis>
</animation>
 
In the above example interpolation is used to tell the rudder how much to move in either direction.  Interpolation can also be used to set up the timing for animations.
In this example which is for the right main landing gear door of the A320 the door is normally closed.  If the gear is to be raised the door will pop open wait for the gear to rotate into the bay and then the door will shut.
<animation>
  <type>rotate</type>
  <object-name>MainGearDr2</object-name>
  <property>/gear/gear[0]/position-norm</property>
  <interpolation>
      <entry><ind>0.0</ind><dep>0.0</dep></entry>
      <entry><ind>0.2</ind><dep>84.0</dep></entry>
      <entry><ind>0.8</ind><dep>84.0</dep></entry>
      <entry><ind>1.0</ind><dep>0.0</dep></entry>
  </interpolation>
  <axis>
      <x1-m>-2.1418</x1-m>
      <y1-m>-0.398918</y1-m>
      <z1-m>-4.6747</z1-m>
      <x2-m>-0.469801</x2-m>
      <y2-m>-0.398918</y2-m>
      <z2-m>-4.67559</z2-m>
  </axis>
</animation>


This document will likely be out of date by the time you read it. Look at the actual XML wrapper files (currently in $FG_ROOT/Aircraft/aircraft-type/Models/) to look at how FlightGear is doing things now. In the future, we'll be adding other animation types, including selecting among different versions of the same object (such as a translucent propeller disk for high RPM), non-rotational transformations, scaling, and conditionals (i.e. draw engine exhaust only above a certain velocity).
This document will likely be out of date by the time you read it. Look at the actual XML wrapper files (currently in $FG_ROOT/Aircraft/aircraft-type/Models/) to look at how FlightGear is doing things now. In the future, we'll be adding other animation types, including selecting among different versions of the same object (such as a translucent propeller disk for high RPM), non-rotational transformations, scaling, and conditionals (i.e. draw engine exhaust only above a certain velocity).


''David Megginson, 11 March 2002''
''David Megginson, 11 March 2002, edited for currency, Jon Bourgeois, 16 Sep 2009''


{{3d}}
{{3d}}
17

edits