# DynDOLOD - Dynamic Distant Objects LOD - Sheson

## Finally I can see my house from here

This document like DynDOLOD is work in progress and may have outdated or missing info.
If something doesn't make any sense or is unclear, please let me know.

## DynDOLOD Worlds.pas and LODGen.pas and LODGen.exe

Skyrim uses three different LODs which are recomputed: Objects LOD in *.bto files, tree LOD in *.btt files, and landscape LOD in *.btr files.

TES5LODGen generates *.bto files and consists of 2 parts: LODGen.pas, a TES5Edit script and LODGen.exe. TES5LODGen offers a few advantages over CK when generating static object LOD. CK static object LOD has to use a texture atlas for all objects which not only limits visual quality but also means a great deal of extra work is required to produce LOD models. TES5LODGen allows the free use of textures like any other full model.

To simply create static object LOD with the default LOD models, apply LODGen.pas which will scan the world for static objects and a builds a static object LOD list that LODGen.exe uses to create the BTO files for the game to render the LOD.

DynDOLOD Worlds.pas uses LODGen.pas and builds upon it by adding static LOD to objects which didn't have any before. DynDOLOD Worlds.pas scans the world for objects that can be either static, animated or dynamic objects. It then creates the extended static object LOD list for LODGen.exe so it can generate static object LOD. DynDOLOD Worlds.pas continues to update DynDOLOD.esp with the data needed to display animated and dynamic object LOD in game.

The major steps of DynDOLOD Worlds.pas:

### (1) scan the data/meshes/terrain/[world]/trees/*.btt files

Build a list of all references for tress that have tree LOD already. Any reference to a tree that has LOD already, doesn't need to be done as object LOD, or vice versa, any tree that has no tree LOD can be done as object LOD.

The scanning process will only work completely reliable when the BTT files were generated with the same load order.

### (2) scan the data/meshes folder for '*_lod*.nif' files that both DynDOLOD and LODGen can use

Scanning is done in a way so that models with the same name found later take precedence. This way it is easy to 'overwrite' meshes with. The scan order is set in the DynDOLOD.ini

Since the whole data/meshes folder is scanned, mod authors that use new assets can provide lod.nifs with their mod and they are automatically discovered and used. Obviously they need to exist as real files, so they need to be unpacked from the BSAs.

Skyrim LOD uses 3 LOD levels, 4, 8 and 16 - basically meaning the distance static LOD objects are visible. Only the largest objects like mountains and huge buildings need LOD in level 16, large structures should be in 8 and obviously the closest level 4 should have LOD from everything.

A simple file naming convention decides the LOD levels a nif is meant for. See the manual section 'How to add your own LOD models'. It is based on the best compromise to match the default game settings. In addition some of the default mesh rules set the 'out of order' rules.

### (3) scan DOOR, ACTI, MSTT, TREE and STAT records

Build a list of any matching base element in DOOR, ACTI, MSTT, TREE and STAT for LODGen and DynDOLOD. Again, matching is done on the full model name and filtered by the mesh rules. By default the LOD meshes settings in the base elememts are ignored, unless the checkbox 'Use original LOD assignment is checked.

CK and LODGen generate static LOD based on the visible when distant VWD flag and the nif files added to the STAT base element MNAM section. For even more coherent visuals DynDOLOD Worlds.pas also matches DOOR, ACTI, MSTT, TREE objects.

For example statues can be an activator and thus have no LOD even if a nif model exists because ACTI records do not provide LOD data like STAT records.

In case of doors or gates the LOD will be static and not reflect open or closed state, but this will still be much better than simply a gab in a stockade fence.

Trees have their own LOD system. However, it has a crucial limit: such LOD trees can only be upright billboards. Trees growing at angles or lying flat on the ground can not be done by this system. Prominently a whole group of trees have no LOD. TES5LODGen for tress LOD with the resources from the DynDOLOD package helps addressing part of the problems.

In addition, since trees/LOD trees are objects too they can be done as object LOD with no limit on orientation. There is an ini option that allows to replace all tree LOD with a visually better LOD object LOD version. It works performance wise, but static object LOD in an attached cell takes much longer to turn off so the models may flicker for a bit. This an experimental setting to play around with.

DynDOLOD Worlds.pas creates an extended version of the static object LOD export list for LODGen.exe by adding lines for object references that have a MSTT, DOOR, GATE or TREE base element.

LODGen.exe can be executed with the export file directly to regenerate static object LOD. This comes in handy when simply updating existing model nif files for example or trying other LODGen.exe options. Click the 'Exceute LODGen.exe' button lower left. Note that the *.bto output path is hardcoded into the export file.

### (4) Scan the world

Scanning the world looks for references that use STAT, DOOR, ACTI, MSTT, TREE base elements in the list built in (3) and either adds them to the LODGen export list or to the internal DynDOLOD list for (10).

If the selected world is Tamriel the process also scans the 5 major towns for references that now have LOD added by (2) and (3). These child worlds have LOD representations of the major structures in the parent world. DynDOLOD Worlds.pas adds the same type of representations for select objects that now have LOD.

the mesh rules filters determine how a reference should be processed. Also the LOD tree list is used to filter out all references to trees that already have LOD.

If a reference has the neverfade flag set, the flag will be unset. In case the rerference can static LOD for TES5LODGen it is added to the export file for LODGen.exe. If the reference is a dynamic object it will be added as a DynDOLOD object. See (11).

### (5) Add manual references

This adds manual references from DynDOLOD_manual_refr_[worldname].txt into the world if it matches. This may be needed in case the normal processes are not enough.

### (6) Add town references

If scanning the world in (4) found any child town references a new reference for either TES5LODGen or DynDOLOD will be added in to the world.

### (7) Write export list for LODGen.exe

Save the export file for LODGen.exe.

### (8) Execute LODGen.exe

Execute the external tool LODGen.exe to generate the static object LOD from the export file.

### (9) Setup the FarGrid and NearGrid for DynDOLOD

DynDOLOD Worlds.pas adds a number of invisible ACTI references that help track the player character and switch on or off DynDOLOD objects. This step can take a bit of time, but helps to make sure that the papyrus scripts can work as passive and as fast as possible using default in-game functions and features.

### (10) Add DynDOLOD references for dynamic/animated/full models

A DynDOLOD object is a copy of a original reference. While the original reference is an object that is loaded in the active cells, the DynDOLOD object is enabled when it is outside the active cells and disabled when in the active cells.

Working with a copy means that the original reference is not modified by DynDOLOD scripts. By using a copy DynDOLOD can freely enabled or disabled objects based on distance to the player and enable parents at the same time. Because DynDOLOD checks the original reference for its current enable status the system works when quest scripts manipulate the original object directly without the use of enable parents.

In this step the DynDOLOD Worlds.pas adds the distinct DynDOLOD references with their needed settings and flags.

The DynDOLOD base elements for these references were already added in (6).

### (11) Consolidate and write data

This ensures the DynDOLOD Mod papyrus scripts have to do as little work as possible when switching on or off DynDOLOD objects. The lookup form lists are sorted and consolidated into as few lists as possible and then written to a json data file for PapyrusUtil.

### (12) Copy grids to child worlds

If there are child town worlds in the selected worldspace, the grids are copied. This allows dynamic LOD objects in the world to be visible from inside the child worlds.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.