Draped Roads RFC

This RFC describes a possible enhancement to the road format for scenery. =Overview=

Definition
A scenery element is "draped" if its vertical component is taken from the terrain mesh. Examples of draped scenery include objects, draped polygons, and runways. Examples of non-draped scenery include beaches and roads.

If the underlying mesh is changed, draped elements take on the height of the new mesh; undraped elements may appear underground or floating.

Draped elements may be "naively" draped - that is, simply take on the contours of the underlying terrain without regard to the effect. For example, runways are naively draped; if there is a spike in the underlying mesh, the runway takes on the spike. (Thus it is necessary to heavily process the underlying mesh below a runway.)

Draped elements may be "crudely" draped - that is, the draping may be imperfect relative to the mesh. OBJs are somewhat crudely draped in that the center of the object touches the terrain, but the object itself is not bent. Facades are crudely draped in that only their corners are draped. Runways are not crudely draped - the runway is broken into as many small pieces as necessary to naively drape.

Motivation
The motivation to have roads become draped is two-fold:
 * If runways are draped, third parties can build road packages that are not particular to an underlying mesh tile; such a package can be compatible with multiple versions of the global scenery and/or custom meshes.
 * An undraped mesh needs fewer vertices - currently roads must have vertices inserted at every edge in the terrain mesh. Draped roads might take up less DVD space.

Problem
Neither naive nor crude draping are adequate for roads - a road that is only draped at its vertices may form a huge bridge or plow through the ground; a road that is naively draped may have too high of a gradient to loo plausible.

The draping algorithm must preserve an amount of control for authors. =Proposed Solutions=

File Format Changes

 * A road type can be either draped or undraped. All existing road types are undraped - draped roads types are created by a new .net file directive.


 * Undraped roads continue to be specified by MSL elevation at every node point.
 * Draped roads would contain a "layer" number (0 meaning on ground or a positive integer for higher layers) at any point where a draped road crosses another road. Shape points would have a Z of 0.
 * Draped roads would (in the .net file) be defined in terms of two non-draped roads: a type to use when the draped road touched the ground, and a type to use when the draped road was elevated. X-Plane would dynamically pick the non-draped subtype based on the actual draping results.
 * Draped roads would contain (in the .net file) gradient limitation information for draping.
 * X-Plane would allow the elevation of a junction from two roads to have differing layer (Z) values. Currently this is illegal, and a unique junction must be used for each "layer" of an interchange.  With this modification, a single junction could be used for a stack of intersections.
 * X-Plane would _require_ that a junction (with vertical separation) exist for any draped road that crosses over/under another draped road; X-Plane would not guarantee vertical clearance without this.

Draping Algorithm
When building roads, X-Plane would drape all draped road types to put them as close to the ground as possible while ordering layering values as much as possible and limiting slope as much as possible.

''Note: "as much as possible" is hand-waiving; it will be possible to make road grids that cannot meet all constraints requirements, e.g. an interchange that is too small for ramps to connect without violating slope constraints. The spec makes no guarantees for how constraints are prioritized.''

Road points would be moved upward to:
 * Clear terrain
 * Limit slope (e.g. if a neighboring point must be a lot higher than me, and my slope is limited, I must be raised)
 * Clear other roads (e.g. if I am layer 1 at a junction I must be at least N meters from layer 0.

Open Issue: how is the clearance between road layers determined?

Connecting Draped & Non-Draped Roads
It is legal to connect draped and non-draped roads. For example, it might be desirable to connect a draped highway to a non-draped suspension bridge that has been pre-built at the real-world "deck height".

If a junction contains any non-draped roads, the junction is considered "non-draped" and has the following behavior:
 * All roads into the junction are connected, regardless of their height coordinate.
 * The height of the junction is taken from one of the non-draped roads.

Thus a non-draped junction "sucks in" and connects draped roads.

Layouts with nested non-draped junctions can still be created by using multiple colocated non-draped junctions.

Power Lines
Power lines present some different draping parameters:


 * A powerline does not need to be noded along the contour it cuts.
 * A powerline does need to be noded to a maximum span length.
 * A powerline does need to be noded peak-to-peak, so that the wires do not hit peak areas.

These limits can be met by having the type info for a draped powerline indicate powerline draping rules instead of road draping rules.

There is one other requirement: that a powerline not be noded (nodes induce towers) where it crosses roads.

One way to do this would be to include road-crossing junctions in the power lines, and let X-Plane intentionally un-node the powerline at that point. Another option would be to have some kind of "tag" on powerline shape points to indicate: this shape point must NOT be noded.

Open Issues
The AGL of a surface road can only be increased to meet gradient limitations - that is, we can only make bridges, not tunnels. An overpass can be "lowered" (that is, we can accept reduced clearance). This can cause a road to become elevated and collide with a bridge that is a fixed AGL above it.

This condition may occur inconsistently: the bridging and sloping rule will depend on the 2-d line channel across a 3-d height-field. In other words, a road that runs along a ridgeline may not need adjustment, while a road that runs down the ridge may need significant adjusting.