Ground polygons (ASM tweak): Difference between revisions

From FSDeveloper Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
By default the source code generated by GMax is not really suitable to draw ground polygons with. As a result of this "wrong" code you can see shimmering with the mesh below and also the wrong display of shadows. With the tweaks described in this article, you will be able to turn your polygons into proper ground polygons again.
How to create ground polygons with GMax is an often asked question. This article will try to guide you through that process, as it takes some tweaking the get the correct results.


One note before we continue, this tweak is for the Fs2002 gamepack only. The new Fs2004 MDL structure is totally unsuitable for ground polygons and I discourage anybody from using a MDL for ground polygons. Instead use the old gamepack for them.
How to create your ground polygons is outside of the scope of this article. Basically you can just draw them like any polygon and then map the texture you want on it. The only difference is that the polygons are on the ground, so they have a z-coordinate of zero.


To draw correct ground polygons, you need to make the following changes. First find the following lines of code in your main ASM file:
Please note that if you want your ground polygons to be compatible with FsX (with the SP1 installed), you need to make sure that the vertices of your ground polygons are not further away from each other then 100 meters. So if you have a big polygon, you might have to split it into smaller pieces. If you keep this additional restriction in mind, you will not have trouble with the added earth curvation of FsX.


<pre>OBJECT_0_START label word
==Fs2002 gamepack==
IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767
ADDOBJ OBJECT_0_SCALE
SHADOW_CALL OBJECT_0_SCALE
OBJECT_0_FAIL label BGLCODE</pre>


In this code you need to replace the ADDOBJ command with a ADDCAT command. This defines makes sure the polygons are layered properly and not seen as a 3D object. Also you need to remove the SHADOW_CALL command, as a ground polygon does not cast a shadow on the ground. So after that you code looks like this:
The first complication is that you need to use the Fs2002 gamepack. This is because the MDL format used by the Fs2004 and FsX gamepacks is not really suitable for creating ground polygons. When using them you for example get flickering polygons and the shadow of other objects is also not displayed correctly on it. With the Fs2002 gamepack we can apply some tweaks to prevent these trouble.


<pre>OBJECT_0_START label word
But you can not download the Fs2002 gamepack from the internet, some files only came with the Fs2002 Pro CD. So if you don't own that version of FS (anymore) you have a little problem. A work around is to use MDLCommander with the Fs2004 gamepack and then run the [http://www.fsdeveloper.com/wiki/index.php?title=Saving_X_files_using_MDLCommander X file] that you saved through the Fs2002 MakeMDL manually.
IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767
ADDCAT OBJECT_0_SCALE, 8
OBJECT_0_FAIL label BGLCODE</pre>


As you have probably seen, the ADDCAT command also has an extra parameter. This is the layer number at which you want your polygon to display. If you are trying to place some polygons in a specific order you can use this number to give them the correct sequence.
Be sure that you use the [http://www.scenery.org/tutorials_fs2k2_SDK.htm latest version] of the Fs2002 MakeMDL, as the initial version does not allow you to save the ASM source files that you need to tweak later on. For a basic introduction to saving and compiling ASM source, please refer to this [http://www.fsdeveloper.com/wiki/index.php?title=Beginners_guide_ASM_tweaking article].


One final note. This change only works if your source only contains ground polygons. If you have a mixed source with ground polygons and 3D objects the result will not be as you want. Due to the way GMax structurizes the source code it is not easy to add both a ADDCAT and a ADDOBJ command in one source. For this solution to work correct both commands should call the piece of code they apply to. So the ADDCAT command should call the piece of code with the ground polygons and the ADDOBJ command should call the code of the 3D objects. But in the file GMax makes this code is not separated.
==Tweaking the ASM code==


The best way to solve this problem is to make two source file, one for the ground polygons and another one for the 3D objects. This can be done by selecting all objects belonging to these categories in GMax and then using the ''Export selected...'' option of GMax.
So now that you have saved your ASM source files, it is time to start tweaking them. What we are going to change in the ASM file are a few commands that by default call your polygons as if they are a 3D object. But there is also another call for ground polygons, when this call is used the flickering and shadow problems are solved.


In FsX (with SP1) these kind of ground polygons still work, but to get them to display correctly you need to make sure they do not get to big. It is best to keep your polygon around 100x100 meter in size. If you need to draw a bigger one, just divide it in smaller tiles. All these tiles can still be exported with a single reference point.
So open your main ASM file and look for the following lines of code:
 
  OBJECT_0_START label word
  IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767
  ADDOBJ OBJECT_0_SCALE
  SHADOW_CALL OBJECT_0_SCALE
  OBJECT_0_FAIL label BGLCODE
 
In this code the ADDOBJ command is the one that is calling your polygons as a 3D object. So this is the one we will change in the ADDCAT command used for ground polygons. The ADDCAT command also has an additional parameter that sets the layer of your ground polygons. So this can be used to layer different ground polygons on top of each other. In this article we will set the layer to 8, it is common practice to use only layers that are a multiple of 4 (so 0, 4, 8, 12, 16, 20, ...).
 
We will also remove the SHADOW_CALL command, as ground polygons are not really able to cast a shadow on the ground. So after applying these two tweaks you are code should look something like this:
 
  OBJECT_0_START label word
  IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767
  ADDCAT OBJECT_0_SCALE, 8
  OBJECT_0_FAIL label BGLCODE
 
One final note. This change only works if your source only contains ground polygons. If you have a scene with both ground polygons and 3D objects, use the "Export selected..." feature from GMax to export the ground polygons and the 3D objects seperately from each other.


[[category:Scenery design]]
[[category:Scenery design]]

Revision as of 14:56, 12 July 2007

How to create ground polygons with GMax is an often asked question. This article will try to guide you through that process, as it takes some tweaking the get the correct results.

How to create your ground polygons is outside of the scope of this article. Basically you can just draw them like any polygon and then map the texture you want on it. The only difference is that the polygons are on the ground, so they have a z-coordinate of zero.

Please note that if you want your ground polygons to be compatible with FsX (with the SP1 installed), you need to make sure that the vertices of your ground polygons are not further away from each other then 100 meters. So if you have a big polygon, you might have to split it into smaller pieces. If you keep this additional restriction in mind, you will not have trouble with the added earth curvation of FsX.

Fs2002 gamepack

The first complication is that you need to use the Fs2002 gamepack. This is because the MDL format used by the Fs2004 and FsX gamepacks is not really suitable for creating ground polygons. When using them you for example get flickering polygons and the shadow of other objects is also not displayed correctly on it. With the Fs2002 gamepack we can apply some tweaks to prevent these trouble.

But you can not download the Fs2002 gamepack from the internet, some files only came with the Fs2002 Pro CD. So if you don't own that version of FS (anymore) you have a little problem. A work around is to use MDLCommander with the Fs2004 gamepack and then run the X file that you saved through the Fs2002 MakeMDL manually.

Be sure that you use the latest version of the Fs2002 MakeMDL, as the initial version does not allow you to save the ASM source files that you need to tweak later on. For a basic introduction to saving and compiling ASM source, please refer to this article.

Tweaking the ASM code

So now that you have saved your ASM source files, it is time to start tweaking them. What we are going to change in the ASM file are a few commands that by default call your polygons as if they are a 3D object. But there is also another call for ground polygons, when this call is used the flickering and shadow problems are solved.

So open your main ASM file and look for the following lines of code:

 OBJECT_0_START label word
 IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767
 ADDOBJ OBJECT_0_SCALE
 SHADOW_CALL OBJECT_0_SCALE
 OBJECT_0_FAIL label BGLCODE

In this code the ADDOBJ command is the one that is calling your polygons as a 3D object. So this is the one we will change in the ADDCAT command used for ground polygons. The ADDCAT command also has an additional parameter that sets the layer of your ground polygons. So this can be used to layer different ground polygons on top of each other. In this article we will set the layer to 8, it is common practice to use only layers that are a multiple of 4 (so 0, 4, 8, 12, 16, 20, ...).

We will also remove the SHADOW_CALL command, as ground polygons are not really able to cast a shadow on the ground. So after applying these two tweaks you are code should look something like this:

 OBJECT_0_START label word
 IFIN1 OBJECT_0_FAIL, image_complex, 2, 32767
 ADDCAT OBJECT_0_SCALE, 8
 OBJECT_0_FAIL label BGLCODE

One final note. This change only works if your source only contains ground polygons. If you have a scene with both ground polygons and 3D objects, use the "Export selected..." feature from GMax to export the ground polygons and the 3D objects seperately from each other.