Modelling guidelines

From FlightGear wiki
Jump to navigation Jump to search

When modelling an aircraft, building or any other 3D model, you are encouraged to follow the modelling guidelines outlined in this article.

Feel free to add/modify. (please leave a comment in the talk page for radical modifications).

Definitions

Model
The file with the 3D model.
Object/mesh
Part of the model file. A model can contain several objects or meshes.
Texture
Image file (.rgb, .png) that are draped around the model.

Modelling guidelines

  • Vertices are free up to a point - use as many as you need.
  • Many small (in vertex numbers) objects/meshes have a far worse negative impact on performance than a single object/mesh with very high vertex numbers.
  • Combine all different parts of the model into one single object/mesh, with the exception of parts that need to be animated, or of transparent parts.
Blender
Select some objects and press Ctrl+J to join them into one Object. The new object origin/transform/orientation/name will be based on the ones of the last object selected.
  • Use different unique names for each of the objects in a model file. Even more so when the different parts need to be animated.
  • Make all faces of the objects single sided.
  • If you need a part of the model to be visible from both sides, duplicate it in place and flip the normals. The extra geometry overhead is negligible compared to the extra work generated by double-sided faces.
  • Separate transparent parts into their own objects.
Blender
Go into edit mode, select the part of the object that you would like to separate and press P.
  • Assign to all transparent objects at least the model-transparent effect:
	<effect>
		<inherits-from>Effects/model-transparent</inherits-from>
		<object-name>Transparent-object1</object-name>
		<object-name>Transparent-object2</object-name>
		<object-name>Transparent-object3</object-name>
		<object-name>other-Transparent-object</object-name>
	</effect>
  • The interior should be a separate model. Having it separate enables delayed loading of such models in multiplayer/AI contexts.
Only one instance of the tag is allowed for the whole aircraft. Such a model is specified as follows in the XML file:
		<model>
			<usage>interior</usage> <!--make sure to have this tag-->
			<path>Models/your-interior-model.xml</path>
		</model>

If your model require an <offsets> section, you must move the <offsets> section in the children XML like:

your/aircraft/Models/aircraft.xml:

<PropertyList>
  <path>path/to/model.ac</path>
  <model>
    <path>your/aircraft/Models/Interior/model.xml</path>
    <usage>interior</usage>
  </model>
  ...
</PropertyList>

your/aircraft/Models/Interior/model.xml:

<PropertyList>
  <path>path/to/another/model.ac</path>
  <offsets>
    <x-m> -1.91552 </x-m>
    <y-m>  0.00000 </y-m>
    <z-m>  0.23706 </z-m>
    <roll-deg>    40.0 </roll-deg>
    <pitch-deg>   35.0 </pitch-deg>
    <heading-deg> 60.0 </heading-deg>
  </offsets>

  <model>
    <path>path/to/another/model.xml</path>
  </model>
  ...

Texturing guidelines

  • Combine as many parts of a single model to a single texture as you can. The maximum texture size is 4096 x 4096 pixels.
  • Do not assign multiple textures to the same object/mesh. The object will be split so as to have a single texture per mesh.
  • Do not use different parts of a single texture for different models. Instead, split the texture into smaller parts.
  • If using the same texture on multiple models, use a single file, do not make different copies.
  • Prefer texture replacing animations to textranslate for models that spend large amounts of their time in one state (day/night animations).
  • Avoid transparency like the plague, it kills frame rate like nothing else. Remove the alpha channel from textures if they are non-transparent.
GIMP
Go to Layers > Transparency > Remove alpha layer.
Inkscape
Go to File > Document Properties and set the Background to a non transparent colour (preferably black).
  • Hive off transparent parts of textures into their own textures.
  • Use power of two dimensions for textures (in essence 2n, for example 256x256, 512x1024). Do not worry if your image would get stretched in the texture, you can fix that with the mapping on the model.
  • Do not have textures with the image in one corner and the rest unused.
  • Recommended texture format is: .png. In general any texture format supported by OSG could be used, but be aware of varying cross-platform support for such formats, or of lossy compression.

Multiplayer property usage

When your model is loaded over multiplayer instead of the property tree starting at the top (/) your model will be loaded with a property tree root of ai/models/multiplay[#]. It is important that you use the right properties inside your model. This is possibly one of the most commonly misunderstood aspects of the correct way to use properties.

  1. The general rule is that you must never include a leading / on any property path.
  2. The exception to this rule is the few properties that relate to the FlightGear instance on which the model is running. An example of this is the properties related to environmental lighting.
  3. Writing or modifying an absolute property should never be done.

Notes

  • All model XML files are loaded such that their property root is correctly adjusted already, and thus sim/model will be either /sim/model or ai/models/carrier[0]/sim/model, or ai/models/multiplay[0]/sim/model.
  • Any Nasal code (loaded from the model XML file) needs to use the property root that is passed into the model XML file in cmdarg (you can see this in the model XML file for the F-14 [GitHub]/Zaretto/fg-aircraft/develop/aircraft/f-14b/Models/f-14b.xml#L25

Improving models for best FlightGear performance

Using Multiple Models with varied detailing
To set faces to Singlesided (Blender), deselect the Doublesided button

Mesh

  • In a single model, use a single mesh so far as possible. Note that this doesn't mean that every node must be linked to its object with an edge (e.g. a line of trees can be easily a single object.) Only have the separate objects if you need them for an animation or parts that use a transparent texture (any object using more then one texture is anyway spitted by the rendering engine.)
  • Delete unseen faces such as faces inside the model, but remember that the Rembrandt renderer needs closed meshes to cast shadows correctly, so you'll often want to keep the ones below.
  • Remove "line faces", which are faces whose points are in the same line.
  • Don't forget to remove double vertices (i.e. vertices sharing the same coordinates)
  • See Howto:Decrease the number of faces.

Single sided / double sided

  • Set all the faces of the model to SingleSided. DoubleSided faces are very expensive to render properly. If a face needs to be displayed from every view angle use two faces with opposite normals rather than a Doublesided one (the overhead from the extra geometry is far lower than the overhead of doublesided faces)

Textures and Materials

Cquote1.png Modern graphics cards can handle very large textures and huge numbers of vertices with minimal frame rate impact. A typical scene in FlightGear (with clouds, buildings rivers, roads...) has millions of vertices which simply dwarfs a 17K aircraft making the aircraft model an insignificant factor. The general rule is use enough vertices and large enough textures to make things look right and no more. More recent aircraft efforts tend to have much higher vertex counts, much larger textures and a lot more detail then older work because of how capable modern hardware is. It is not unusual to see newer aircraft exceeding 100K vertices. For example the P-51D that will be released with 3.2 has an external model that is slightly over 100K vertices and this had a minimal frame rate impact on my (newer high end) hardware compared to the old 10K external model.


If you can't see the difference between using a 512x512 instrument texture compared to a 256x256 texture then use the smaller texture. But if you can see the difference then use the larger texture. On modern hardware the difference in frame rate will be very small but it may impact those with older/slower/obsolete hardware in a noticeable way. All of the instruments in the P-51D are 512x512 for larger gauges or 256x256 for smaller gauges and at least to me they have a sharp appearance even when zoomed in fairly close. Many older aircraft use 128x128 textures for instruments but to me at least on the larger instruments on a very high resolution monitor these textures are a little bit fuzzy in appearance. The other thing I do is I create the textures at much higher resolution and then scale it to final size. This allows the scaling algorithm in the graphics package to apply anti aliasing during the scaling process which I think helps make the smaller textures look good since it reduces the appearance of jaggies.


— hvengel (Fri Aug 08). Re: key + animation.
(powered by Instant-Cquotes)
Cquote2.png
  • Use Materials on Objects instead of textures where possible, but...
  • ...avoid mixing textured and untextured geometry in the same model. Build the coloring into the texture map instead. This is to prevent that the object gets split, and anyway, the AC format supports only one texture per object.
  • Textures must be a power of two, or they will be resized at loading, and cause issues to some users.
  • Avoid using big textures: 512x512 is mostly enough for most models.
  • Use a single texture. However, if your model absolutely needs alpha texture and another part of the model is opaque, you should use two textures: one with alpha and the other without.
  • Don't use alpha in texture when it is not needed: transparency is not easy to deal with, and often causes artifacts.

Effects

  • Shader effects (like lightmaps, normalmaps...) and Rembrandt lights are not affordable by everyone's machine, so try to provide alternatives. However, remember also that FlightGear provides options to adjust such effects.

Level of Detail (LOD)

Note  Note that range animations often used for LOD are very expensive (any time you move, every range animation must be evaluated), and give a real advantage only if they remove a very large amount of details (like 1000-2000 triangles), so it's not useful in many cases of for example scenery objects or cockpit details.
Tip  Instead of using range animations for each little detail you could group many details together and do the range animation for them all, for example having one range animation for an entire cockpit instead of several dozens.
  • If a model has to be detailed to a very high degree, use multiple objects with different levels of detailing, and switch between them based on LOD with a range animation, or split the detailed parts to make them a couple more objects that add details incrementally.
  • An alternative, less expensive way to support LOD is applying a select animation, that can hide an object based on some property, for example hiding a cars side mirrors if "detailed" level is at less than 1500m (which is the default), indicating that the user has a less powerful machine. It is less flexible, but allows everyone to enjoy your models.

Other

  • With modern graphics cards, the amount of objects can have a higher impact on performance than the amount of triangles/vertices.
  • Textures, transparency, .xml included sub-models: The things that kill frame rate in FlightGear. Try to avoid them.
  • Also avoid smooth shading when possible, but don't be afraid to use it for curved surfaces where it really has an impact on model quality.

Related content

Developer mailing list threads