This tutorial covers the process of adding multiple detail levels to a (static) dts shape. We'll be continuing where we left off in Tutorial 1 - Exporting Meshes and Textures, using the same "security fence" model. If you'd like, you can download the completed model from tutorial 1, or use the one that you created. Since I'll be referring back to some of the things that I talked about in tutorial 1, I'd recommend that you complete tutorial 1 before attempting this tutorial. I'd also strongly recommend reading through the LOD - Levels of Detail article to familiarize yourself with the concepts involved before beginning this tutorial.

(screenshot of the model created in Tutorial 1 - this model is our starting point for this tutorial)
Step 1 - Preparing the file
First we're going to open up the Tutorial1.blend file that was created in Tutorial 1 and save it under a new name: Tutorial2.blend. Click "File->Save As..." and enter Tutorial2.blend as the new file name.


Note: I've saved my Tutorial2.blend in the same folder as my Tutorial1.blend.
Next, we're going to open the exporter user interface and change the output file name. Because the exporter's settings are stored within the .blend file, we've still got the settings from Tutorial1.blend, including the default output file name of Tutorial1.dts. In order to avoid confusion, we're going to reset the output file name to Tutorial2.dts. Open the exporter GUI and navigate to the "General" panel. Click the "Default" button to the right of the "Output path and file name" text box:

After clicking the "Default" button, you should see the file name change to Tutorial2.dts.

Go ahead and hit the Export button and verify that you've got a new Tutorial2.dts file in the chosen output folder. Close the exporter GUI (esc key) and re-save your .blend file. After changing the exporter's settings, it's a good idea to close the exporter and re-save the .blend file to ensure that the newest exporter settings are saved.
Now that we've got our file prepared, we're ready to begin.
We're going to be setting up 3 levels of detail for our fence model: Detail1, Detail75, and Detail150. The "size" numbers on the end of each detail level name correspond to the width in pixels of the shape's bounding box at which each detail level begins to display. Unfortunately, Torque's detail level switching mechanism does not function perfectly.
Aside - Torque's detail level switching mechanism and why it is wonky
There are two main sources of "inaccuracy" in Torque's detail level switching mechanism: The default value of the "detailAdjust" preference setting, and the fact that the math is "hard coded" for a 800x600 screen resolution.
The default value of the "detailAdjust" Torque script preference is set to "0.45". If you look in TGE's /client/defaults.cs or /client/prefs.cs files, you'll see the following line:
$pref::ts::detailAdjust = 0.45;
This setting causes the detail level "size" numbers to be multiplied by 1.45 for the purposes of determining when to switch detail levels. Remember that the "size" value corresponds to the width of the shapes overall bounding box in pixels as displayed on the screen. It may be tempting to set this value to "0", but I would not recommend doing so. Almost all of the pre-made dts files included with Torque and available for purchase elsewhere are set up to take this default 1.45 detail level adjustment into consideration. This setting has been the default for a long time now, so it's probably just better to be aware of it and to work with it instead of setting it back to 0.
Here are some screenshots that I've taken in TGE 1.5.2 at 800x600 resolution that illustrate the effects of the default detailAdjust value.


As you can see, when running TGE at 800x600 resolution the values are approximately what we'd expect.
75 * 1.45 = ~108.75 (pretty close)
150 * 1.45 = ~217.5 (also pretty close)
The second issue that I mentioned is that Torque's detail level selection mechanism is hard-coded for a screen resolution of 800x600. The further away the actual screen resolution is from this assumed resolution, the more inaccurate the detail level switching becomes. This is especially true for widescreen video modes. Here are some more screenshots to illustrate the issue:




Note: 1680x1050 is a common "native" resolution for 22 inch widescreen monitors. The situation is even worse on 24 inch widescreen monitors with higher native resolutions.
As you can see, the higher the resolution, the sooner the detail level switching happens. This basically means that people who are running in a higher resolution will see more detail at a given distance than people running at a lower resolution. I'd recommend tuning your detail levels using a resolution of 1024x768, as that is pretty much the "base" resolution for running games nowadays. Anyone running your game in a higher video resolution will see more detail than they should at a given distance, which isn't really too bad, but may affect performance somewhat. Use your best judgment.
OK, with that out of the way, let's continue with step 2 :-)
Step 2 - Setting up the Detail Levels in the exporter user interface
We're going to be setting up 3 levels of detail for our fence model: Detail1, Detail75, and Detail150. The "size" numbers at the end of each detail level name correspond to the width in pixels of the shape's bounding box at which each detail level begins to display. There is no special significance to the detail level size numbers that I've chosen for this tutorial, feel free to tune the size numbers as you'd like for your own models. I'd recommend using 2-5 different detail levels depending on the complexity and polygon count of a particular model. Using too many detail levels may actually hurt performance.
Detail150 is the "highest" detail level in the model (the most detailed). We're going to use the meshes that we already created in Tutorial 1 "as-is" for the Detail150 detail level.
Open up the exporter user interface and navigate to the "Shape->Detail Levels" panel:

As you can see in the above screenshot, we currently have one detail level defined (Detail1) that covers all layers in the Blender Scene. We're going to change the "Min Pixel Size" number to 150 by clicking in the center of the "Min Pixel Size" control and entering 150 as the new value:


Now we're going to change the layers assigned to this detail level. Right now, objects in all layers are exported in Detail150. We're going to change the layer assignment so that only objects in layer 1 are exported as part of the Detail150 detail level. Click the first layer button on the Upper-left next to the "Use Layers:" label:

Layer 1 is now assigned to Detail150. Note: multiple layers can be assigned to a single detail level by holding down on the "shift" key while clicking the layer buttons.
Now we're going to crate 2 more detail levels and assign layers 2 and 3 to the new detail levels. At the top of the exporter's detail levels panel, click the "Add" button. A new detail level should appear in the list:

Notice that the exporter has helpfully set the size of the new detail level to 75 for us (half the size of the next highest detail level).
Next we're going to assign layer 2 to the Detail75 detail level. Click on the layer button for "layer 2" in Detail75's "Use Layers" buttons:

Now we're going to add our final "Detail1" detail level and assign layer 3 to it. Go ahead and do so now. The Final detail levels list should look like this:

Before we move on to the next step and begin creating the objects for Detail75 and Detail1, let's make sure that all of the objects that are currently in the scene are assigned to layer 1.
Move the mouse cursor over the 3d view and press the 'a' key once or twice to select all objects. Press the 'm' key to bring up the layer assignment dialog. Click the button corresponding to layer 1 and then click the "OK" button to move the selected objects to the given layer:

Step 3 - Setting up the objects for the other detail levels
Now we're going to create the objects for Detail75 and Detail1 and assign them to layers 2 and 3 respectively. There are several ways to go about creating the "less detailed" versions of the Detail150 objects; I'm going to do it the easy way using Blender's built-in "Polygon Reducer" script.
First, select the "Pillar0" object by right-clicking it in the 3d view. Next, select the "Pillar1" object by shift-right-clicking it in the 3d view. Both objects should now be selected:

Press "shift-d" to create a copy of the two pillars. Blender starts a "move" operation automatically when objects are duplicated; right-click to cancel the automatic move operation.
Note: If you recall from tutorial 1, "alt-d" creates a linked copy of an object that shares the same datablock (editing a linked copy also affects the original and all other linked copies). "Shift-d" creates an independent copy of an object that can be edited separately from the original. The two original pillars share the same datablock. Editing one also affects the other. When we select both of the original linked pillar objects at the same time and duplicate them using "shift-d", we end up with two new linked pillar objects that share a new datablock. The new pillar objects are linked to each other, but not to the originals. This means that editing either of the new pillar objects affects the other new object, but not the original pillar objects. If we had duplicated the pillar objects one at a time instead of duplicating both at the same time, we would have ended up with two new completely independent pillar objects. If you're thinking "huh?" at this point, don't worry about it too much :-) You'll get used to using linked objects as you get more comfortable with Blender. Alternately, you can avoid using them in your own models if you find the concept too confusing, but for this tutorial we're going to continue using them :-)
Now we're going to move the new pillar objects to layer 2. With the mouse cursor over the 3d view, press the "m" key and select layer 2 from the detail level assignment dialog that appears. Press the "OK" button to complete the layer assignment operation.

Now we're going to switch the layer "view" in Blender's 3d view window so that it only shows what is in layer 2. You can switch between layers in the 3d view by clicking on one of the layer buttons in the header of the 3d view. Click the button corresponding to layer 2 in the 3d view's header:

You should see the two new pillar objects that we just created and moved to layer 2. Since these objects are the only objects in layer 2, they should be the only objects that are visible when the 3d view layer is set to layer 2.
Note: you can view multiple layers at once in the 3d view by holding down on the shift key while clicking the layer buttons.
IMPORTANT: As I mentioned in Tutorial 1, the exporter uses a naming convention to group Blender objects that are assigned to different Levels of Detail into DTS objects which contain meshes for each detail level. The exporter chops the Blender mesh names at the last "." in the mesh name. This means that a Blender object called "Pillar0" in one detail level will be matched up with an object called "Pillar0.001" in another detail level. The reason that this naming convention was chosen is that Blender automatically tacks a number on to the end of object names when they are duplicated. Creating a duplicate of the two original pillars in layer 1 has resulted in two new pillar objects named "Pillar0.001" and "Pillar1.001", which is exactly what the exporter is expecting to find. See LOD - Levels of Detail for more information.
Note: It doesn't really matter what comes after the last "." in the mesh name. If you wanted to add a ".LOD1" suffix to all of the meshes in the highest detail level and a ".LOD2" suffix to all of the meshes in the second highest detail level that would also be perfectly fine. Mesh names can also contain multiple "." characters. For example, "myMesh.base.LOD1" and "myMesh.base.LOD2" are both translated to a dts object name of "myMesh.base". Only the last "." and everything after it is considered part of the suffix and is discarded. If you choose to ignore the naming convention, the exporter will complain loudly :-)
Now we're going to run Blender's "Poly reducer" script to reduce the triangle count of the new Detail75 pillars. Split the 3d view into two windows (if you don't already have a spare window visible) and open up a Blender Scripts window. If you're unsure how to do this, see Blender Survival Guide - Working with Blender windows. Select one of the new pillar objects in layer 2 by right clicking it. It doesn't matter which one you select since they are both sharing the same datablock. With one of the pillars selected in the 3d view, select "Mesh->Poly Reducer" from the "Scripts" menu of the scripts window:

Use the default settings in the Poly Reducer dialog that appears:

Click "OK" to complete the poly reduce operation. If you toggle the 3d view layer back and forth from layer 1 to layer 2 you should see that the new pillars now have slightly less detail than the old pillars. If you check the triangle count on the new pillars it should be roughly half the triangle count of the Detail150 pillars (remembering that the Detail150 pillars are made of quads and not triangles, and that the "Triangulate" option is enabled by default in the poly reducer script options).
Next up, we're going to create the pillars for the Detail1 detail level (layer 3). We're going to start by duplicating the original "high detail" pillars in layer 1 again. Switch the layer in the 3d view back to layer 1 and select both of the original pillars again. Duplicate them by pressing "shift-d" and then right-click to cancel the automatic move operation. Press 'm' and then select layer 3 from the layer assignment dialog and hit "OK". You should have two new pillars in layer 3 called "Pillar0.002" and "Pillar1.002".
Select one of the pillars in layer 3 and run the poly reduce script again. This time change the "Poly Reduce" setting to 0.25:

Hit "OK" to complete the poly reduce operation. The new pillars in layer 3 should now have a triangle count that is roughly 25% of the original pillars in layer 1. The three sets of pillars should look something like this in edit mode:

(above: Detail150 pillar in edit mode - triangulated for an apples-to-apples comparison, remember that quads are actually made up of two triangles each)

(above: Detail75 pillar in edit mode - roughly half the triangle count of the Detail150 pillar)

(above: Detail1 pillar in edit mode - roughly one quarter the triangle count of the Detail150 pillar - it's a bit lopsided but we won't be able to tell when it's far away)
Now we're ready to create the lower detail versions of the fence and barbed wire meshes. The fence can't really be optimized any more than it already is; it's just a double sided quad (4 triangles). We're going to use a nifty trick to avoid having to copy the fence mesh. Instead of copying the mesh, we're just going to assign it to all three layers. In fact, let's go ahead and do the same thing with the barbed wire mesh, since it can't really be simplified much either.
Switch the 3d view layer back to layer 1 and select both the fence and barbed wire meshes. With both meshes selected, press the 'm' key to bring up the layer selection dialog:

While holding down on the shift key, click the buttons corresponding to layers 2 and 3:

Click "OK" to complete the layer assignment operation. If you switch between the first 3 layers in the 3d view, you should now see the same fence and barb wire meshes in all 3 layers. The exporter also sees them in all 3 layers and will use the same fence and barbed wire meshes for all 3 detail levels. Pretty neat trick, huh? :-)
Now we're going to do the same with the "wire holder" mesh, but instead of assigning it to all 3 layers, we're only going to assign it to the first two. The result of this will be that the "wire holder" shows up as-is in the first two detail levels (Detail150 and Detail75), but blinks out of existence when Detail1 is being displayed. The reasoning for this is that the player won't be able to see this mesh at that distance (under ~75 pixels) anyway since it's so thin.
Select the wire holder mesh and assign it to only layers 1 and 2 by pressing the 'm' key and selecting those two layers in the layer assignment dialog that appears. Press "OK" to complete the layer assignment operation. The 3 layers that we're using should now look like this:

(above: layer 1 - Detail150)

(above: layer 2 - Detail75)

(above: layer 3 - Detail1)
Go ahead and save your file now.
Export the file to DTS and check it in Showtool pro or Torque. You may want to adjust the detail level "size" numbers if the switching is happening too soon.
Note: You may recall that we used "hierarchical linking" in Tutorial 1 to control the drawing order of our translucent meshes. In this tutorial we did not need to repeat those steps for each additional detail level. The exporter takes the object hierarchy from the highest level of detail and uses the same hierarchy for each subsequent LOD. As long as the mesh naming convention was followed, the drawing order for the translucent meshes in the other two detail levels should also be correct. If you see issues with the drawing order in the other two LODs, double check that your meshes are named correctly.
This concludes Tutorial 2. In Tutorial 3 we will be adding Collision and LOSCollision meshes to the shape so that the player can't walk through it.