Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

AC files: Basic changes to textures and colors

From FlightGear wiki
Jump to: navigation, search

Ac files (extension .ac) are the basis of all scenery and aircraft models in FlightGear. Knowing how to read and change an AC file can be useful sometimes, e.g. when you quickly want to change a color or use another texture. This article shows you how to modify the material and texture entries.

Materials

rgb 1 1 0
amb 0.72 0.64 1
emis 1 0 0
spec 0 1 0
trans 0.5

When you open an AC file in a text editor, you will see a number of material lines like this:

MATERIAL "default" rgb 0.5 0.5 0.5 amb 0.4 0.4 0.4 emis 0 0 0 spec 0.2 0.2 0.2 shi 128 trans 0

This line defines the material default for all poly structures that use this material. It is the default color of .ac files produced by the SketchUp to AC3D exporter.

We will now go through that line bit by bit:

rgb 0.5 0.5 0.5

Color: This material is medium grey. Red Green Blue (of which the color is composed) are all medium strong. rgb 0 0 0 is black, rgb 1 1 1 is white. Mix to your needs. In the example to the right, red and green make yellow. (More examples here. Those RGB values can go from 0 to 255, so divide by 255 to get the value appropriate for AC files.)
The examples on the right have been made with the Bo105 material dialog (when using the model, press Ctrl-Y to open it). Of course you can make them in the AC file as well: Open, edit, save, done.
The suggested rgb setting for textures is 1 1 1, which shows the colors on the texture excactly as they were drawn. This is a problem with SketchUp resp. the SketchUp to AC3D exporter. There are two solutions to this:
1. Change the colors to rgb 1 1 1 after export. That means that you have to change them every time you export the model.
2. Or you can set the color of the texture to rgb 1 1 1 already in SketchUp. You will see the textures whiteish in SketchUp, but correctly after export (Correct display of texture colors in the AC file).

amb 0.4 0.4 0.4

Ambient: The ambient is the color of the light that falls indirectly onto the material, i.e. the reflection of sunlight is (almost) not affected. In the example to the right, I have changed the ambient (not the color) to full blue.
As of FlightGear 2.0, the amb setting should duplicate the rgb one. If you leave it at amb 0.4 0.4 0.4 after exporting it with the SketchUp to AC3D exporter, the surface will be all grey when the sun does not shine directly on it. So in our example, the amb value should be 0.5 0.5 0.5, just like the rgb one.

emis 0 0 0

Emission makes things glow. Here, I have set the emission to full red and nothing else. In total dark, the model shines red only, in light it is yellow and red. Also see Howto: Illuminate faces.

spec 0.2 0.2 0.2

Specular means the direct reflection of light from sun/moon to the surface of the object and then to the viewer. When you view the object that will form a specular spot on the object, the color of the specular spot is what is set here. In the example, specular is set to full green.

shi 128

Shi stands for shininess, it determines the size of the specular spot. 0 means large spot, 128 means tiny spot. In general highly polished materials would have higher number, while for example rubber or textile would have lower number.

trans 0

With transparency it get really interesting again. Make things transparent, even without using a texture.

Textures

Texture lines are found anywhere throughout the AC file and look like this:

texture "livery.rgb"

If you have defined this texture and now you are unhappy with it, simply change the file name and the model will use the new texture. For example, if you now want to use a PNG version of this texture, change the line into texture "livery.png". If you want to use a different texture altogether, give it the respective name like texture "thenewtexture.rgb".


Identifying an object

If you write an XML file for your AC model (which you always should), you might want to refer from the XML file to certain objects in the AC file. This is necessary when you want to make certain objects rotate or change their size or illuminate them after nightfall or anything like that.

For example, you might want to load a beacon. Let's say that it is in a file named beacon.ac. Inside the .ac file, the object's name is "Beacon_RED". You can load the model and set the object's name in XML like this:

Key tags:

  • <model></model>
  • <path></path>
  • <object-name></object-name>

<?xml version="1.0"?>
<PropertyList>
  <model>
    <!-- load and name the object model -->
    <path>Lights/Models/beacon.ac</path>
    <nopreview/>
    <object-name>Beacon_RED</object-name>
  </model>
  <animation>
    <!-- set the size of the object model -->
    <type>scale</type>
    <object-name>Beacon_RED</object-name>
    <x-offset>2.0</x-offset>
    <y-offset>2.0</y-offset>
    <z-offset>2.0</z-offset>
  </animation>
  <animation>
    <!-- set the size of the object model based on distance -->
    <!-- at "ind" units (meters?) distance, the size of the object will be multiplied by "dep" -->
    <type>dist-scale</type>
    <object-name>Beacon_Red</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>
  <effect>
    <inherits-from>Lights/Effects/beacon</inherits-from>
    <object-name>Beacon_RED</object-name>
  </effect>
</PropertyList>


The above code might be stored in an XML file named beacon-object.xml. Another XML file would load it using code like this:

Key tags:

  • <model></model>

<?xml version="1.0"?>
<PropertyList>
  <!-- Load and position the Beacon Light model -->
  <!-- Position is in meters from model's center coordinates, 0,0,0 -->
  <model>
    <path>Lights/beacon-object.xml</path>
    <offsets>
      <x-m> 0.0000</x-m>
      <y-m> 0.0000</y-m>
      <z-m> 4.9500</z-m>
    </offsets>
  </model>
</PropertyList>


SketchUp Notes

Unfortunately, when using SketchUp, the SketchUp to AC3D exporter will name every object the same:

OBJECT poly
name "blah"

Here is how you can find an object you are looking for: Every part of the model with a unique material is defined as a new OBJECT poly. This means that you only have to know which material an object uses to find it in the body of the AC file. Every material is given a number, starting from the first material after material "default":

MATERIAL "default" rgb ...
MATERIAL "Color_A07" rgb ... This is mat 1
MATERIAL "Color_D01" rgb ... This is mat 2
MATERIAL "Color_F01" rgb ... This is mat 3

Now we will look for the object further below in the AC file that uses mat 2. It is this one:

OBJECT poly
name "Roof"
numvert 4
-5.245000 10.550000 -0.010000
5.245000 0.060000 -0.010000
-5.245000 0.060000 -0.010000
5.245000 10.550000 -0.010000
numsurf 2
SURF 0x30
mat 2
refs 3
0 0 0
1 0 0
2 0 0
SURF 0x30
mat 2
refs 3
1 0 0
0 0 0
3 0 0
kids 0

As you can see, mat 2 is used in this object. Let's imagine that we know that it is a roof. So now that we have named it Roof we can refer to it from the XML file. Voilà!

Note: When you define a new texture in SketchUp, you can give it a name. Imagine that we use the texture roof1.png and that we name the texture Roof. The name and the texture filename will appear in the AC file. Yet you will still have to rename the object. The SketchUp to AC3D exporter will give you this:

MATERIAL "Roof" rgb

OBJECT poly
name "blah"
texture "roof1.png"

The name of the material does not matter at all, it could be anything. The object name is the important thing for reference from XML. Only after renaming the object you will be able to address it from the XML file. (Or, of course, you can refer to the object "blah", if this is the only object with that name in the AC file.)

When you are modelling in SketchUp and you want to ensure that you can identify one part of it later in the AC file, simply give it a unique color or texture that is not used anywhere else in the AC file. An exception to this method exists where you want your object to be invisible until the .xml file animates it (as with some lighting effects) - in that case you MUST use a unique texture. Failure to use a unique texture in these cases will result in your object not showing in FlightGear.