The order objects are listed in a DSF file (either the OBJ definitions or the actual OBJ instances) is not the same as the order X-Plane will draw them! X-Plane will change the order to maximize frame-rate, and the way it organizes them has changed in 850 (and will change again in futur versions).
Until X-Plane 850 there was no way to control the order of objects (although some packages do rely on X-Plane 840’s behavior and now look funny in 850). But with 850 there is a clean way to control draw order that will work well into the future.
Starting with X-Plane 850, there is a new command ATTR_layer_group…it let’s you override what part of the rendering process your object is drawn in, which is useful in a number of cases. Here’s how it works:
X-Plane draws the scenery in a series of steps or “layer groups”. Because of the way OpenGL transparency and polygon-offset affect Z buffering, X-Plane must draw the terrain first, all decals over the terrain second, 3-d buildings third, and anything translucent (clouds, smoke puffs, etc.) last. Layer groups organize all of the scenery into these catagories.
Objects are normally drawn in the “objects” layer group, which is intended for 3-d buildings, static airplanes, jetways, and anything else you might model with an OBJ. However ATTR_layer_group will let you specify that some objects be drawn earlier or later than others.
The command’s syntax is:
ATTR_layer_group objects 1
Where the name (“objects”, but others are allowed – see the OBJ spec) specifies a group, and the number makes the object be drawn after (positive numbers) or before (negative numbers). Objects with the same group and number are drawn together (in an unspecified order), but X-Plane goes by the numbers.
So for example if you want to ensure that a transparent hanger is drawn after a static plane, use ATTR_layer_group objects 1 on the hanger to draw it after all other objects. To draw some apron lines before the terminal, use ATTR_layer_group objects -1 to draw before buildings.
A few other tips:
- Try to use as few offsets as possible – e.g. try to put all “draw last” objects into the group objects/1 – rather than using a different number for each.
- Avoid using layer groups when they are not needed – they inhibit X-Plane from optimizing framerate.
- If you do not use a layer group, but do use polygon offset, X-Plane sets the layer group to objects with a negative number. This is inhibited when you specify the layer group yourself, so be sure to use a negative offset layer group for polygon offset!
- Try to organize your textures so that one texture is not used in multiple layer groups. For example, if you have translucent buildings that must be drawn later, group them in their own texture.
- Related – try to keep polygon-offset geometry (pavement markings) in their own texture and objects. Share one texture for all markings, but don’t put the markings and object together.
This is a description of what I am planning for the anatomy of the “full scenery tools”. Until now we have only published small utilities (ObjConverter, DSF2Text, etc.). The next scenery tools release should cover a lot more, including the first versions of WED.
First of all, WorldMaker is not part of the next-gen scenery tools. WorldMaker is slowly going away, as functionality in WorldMaker is either moved directly into X-Plane for “live” use (navaid editing) or into the scenery toolset.
The new scenery tools will be a single distribution for all tools. In other words, instead of a download for each tool, you will download one archive that contains all of our tools and support files. They will live together in a single “install” folder.
The distribution will not be based on our installer – more likely they will just be a zip file. The scenery tools total size should be small enough that there is no need to do incremental installs. There is no need to put customized files in the scenery tools folder _ever_, so simply replacing it should be a non-issue.
The scenery tools will be completely separate from X-Plane itself and will have their own release schedule and versioning. The scenery tools contain no x-plane code and will also be available in source.
Some undecided issues:
- What to call the main visual editor. The working name has been “WED” (WorldEditor) but that’s so similar to WorldMaker that I fear total confusion. I am open to naming suggestions.
- Whether to make a distribution or each platform or simply put all the EXEs for all the platforms in one download. I don’t think code size will be so huge as to prevent this.
- Whether to allow the scenery tools to be installed in any folder or to require them to go in /Program Files (Windows), /Applications (Mac) or /usr/local/bin (Linux).
One more change: currently I provide a GUI version and a command-line version for some converter apps. With the new scenery tools, I will provide a command-line version for each converter (like now) and a single GUI tool that can do ANY of the conversions that ALL of the command-line tools do.
In other words, for users who want a UI, you will be able to do model->OBJ conversions, ENV->DSF Overlay conversions, OBJ->OBJ conversions, and DSF<->TXT conversions in a single application. This “swiss army knife” GUI application will be extensible and will be our “master converter”.
So the new scenery tools should include:
- Many command-line tools for low level operation.
- A swiss army knife GUI converter tool.
- A visual scenery editor (WED).
- The AC3D OBJ export plugin.
I do not know what the release date of all of this will be, and I do believe that the tools will come out in stages – that is, the first WED will not edit meshes, the AC3D exporter may not be included in the first release, etc. I don’t want to hold up the availability of useful code (like a WED that can edit apt.dat 850 airports) because other parts are missing (like an AC3D exporter version 3.0).
Please do not email me to ask about release dates; now that X-Plane 850 is final, I am working on scenery tools today. I will post more info as I have it.
Here’s something a little bit surprising about the library: the EXPORT command in a library.txt file cannot replace another file in the same package.
For X-Plane 850 we added cars driving on the left side of the road for New Zealand, the UK, Japan, and other countries that drive on the wrong side of the road. Unfortunately what I did was export two road.net files from the same package – one with a region restriction (to these few countries) and a later one with none.
Consider the sum of these two statements…the result is that in New Zealand, the UK, etc. the sim will use either of the two road.net files, picking randomly.
850 will address this with a new library command. Whereas the “export” command normally provides one of multiple alternatives within a package (but replaces any lower ranked packages), the new “export_exclude” command will replace alternatives both within the same package and within lower ranked packages. Commands are treated sequentially, so an export_exclude should usually be at the top of the library.txt file.
In the distant past I blogged about the “crayon rule“, that is, thet importance of not changing textures a lot during rendering, and how authors can help X-Plane avoid changing textures.
Before X-Plane 8.50 the sim would change textures every time the pavement changed types in an apt.dat file. So if you have an airport layout that alternates concrete and asphalt pavement (the order in the apt.dat file is the drawing order!) then X-Plane would just switch and switch.
X-Plane 8.50 tries to be smarter about this and detect when it can get away with changing your layout order to reduce texture changes, improving framerate.
Here’s my warning: X-Plane is not very smart about this! We try to eliminate unneeded changes but our code isn’t that elaborate and it won’t optimize as well as you can.
The sure-fire way to improve framerate is to group your layouts by pavement type. This will give you the best framerate. If you have to overlap pavement and control the draw order, I recommend using as few groups of pavement types as possible.