C# Class Axiom.Components.Terrain.TerrainQuadTreeNode

A node in a quad tree used to store a patch of terrain.
Algorithm overview: Our goal is to perform traditional chunked LOD with geomorphing. But, instead of just dividing the terrain into tiles, we will divide them into a hierarchy of tiles, a quadtree, where any level of the quadtree can be a rendered tile (to the exclusion of its children). The idea is to collect together children into a larger batch with their siblings as LOD decreases, to improve performance. The minBatchSize and maxBatchSize parameters on Terrain a key to defining this behaviour. Both values are expressed in vertices down one axis. maxBatchSize determines the number of tiles on one side of the terrain, which is numTiles = (terrainSize-1) / (maxBatchSize-1). This in turn determines the depth of the quad tree, which is sqrt(numTiles). The minBatchSize determines the 'floor' of how low the number of vertices can go in a tile before it has to be grouped together with its siblings to drop any lower. We also do not group a tile with its siblings unless all of them are at this minimum batch size, rather than trying to group them when they all end up on the same 'middle' LOD; this is for several reasons; firstly, tiles hitting the same 'middle' LOD is less likely and more transient if they have different levels of 'roughness', and secondly since we're sharing a vertex / index pool between all tiles, only grouping at the min level means that the number of combinations of buffer sizes for any one tile is greatly simplified, making it easier to pool data. To be more specific, any tile / quadtree node can only have log2(maxBatchSize-1) - log2(minBatchSize-1) + 1 LOD levels (and if you set them to the same value, LOD can only change by going up/down the quadtree). The numbers of vertices / indices in each of these levels is constant for the same (relative) LOD index no matter where you are in the tree, therefore buffers can potentially be reused more easily.
Inheritance: IDisposable
Show file Open project: WolfgangSt/axiom Class Usage Examples

Public Properties

Property Type Description
DELTA_BUFFER short
POSITION_BUFFER short

Protected Properties

Property Type Description
mAABB Axiom.Math.AxisAlignedBox
mBaseLod ushort
mBoundaryX ushort
mBoundaryY ushort
mBoundingRadius float
mChildWithMaxHeightDelta TerrainQuadTreeNode
mChildren TerrainQuadTreeNode[]
mCurrentLod int
mDepth ushort
mLocalCentre Vector3
mLodLevels List
mLodTransition float
mMaterialLodIndex ushort
mNodeWithVertexData TerrainQuadTreeNode
mOffsetX ushort
mOffsetY ushort
mParent TerrainQuadTreeNode
mQuadrant ushort
mRend TerrainRendable
mSelfOrChildRendered bool
mSize ushort
mTerrain Terrain
mVertexDataRecord VertexDataRecord

Public Methods

Method Description
AssignVertexData ( ushort treeDepthStart, ushort treeDepthEnd, ushort resolution, ushort sz ) : void

Assign vertex data to the tree, from a depth and at a given resolution.

CalculateCurrentLod ( Camera cam, float cFactor ) : bool

Calculate appropriate LOD for this node and children

Dispose ( ) : void

FinaliseDeltaValues ( Rectangle rect ) : void

Promote the delta values calculated to the runtime ones (this must be called in the main thread).

GetChild ( ushort child ) : TerrainQuadTreeNode

Get child node

GetLodLevel ( ushort lod ) : LodLevel

Get the LodLevel information for a given lod.

GetSquaredViewDepth ( Camera cam ) : float

GetWorldTransforms ( Matrix4 xform ) : void

Load ( ) : void

Load node and children (perform GPU tasks, will be render thread)

MergeIntoBounds ( long x, long y, Vector3 pos ) : void

Merge a point (relative to terrain node) into the local bounds, and that of children if applicable.

NotifyDelta ( ushort x, ushort y, ushort lod, float delta ) : void

Notify the node (and children) of a height delta value.

PointIntersectsNode ( long x, long y ) : bool

Returns true if the given point is in the terrain area that this node references.

PostDeltaCalculation ( Rectangle rect ) : void

Notify the node (and children) that deltas are going to be calculated for a given range.

PreDeltaCalculation ( Rectangle rect ) : void

Notify the node (and children) that deltas are going to be calculated for a given range.

Prepare ( ) : void

Prepare node and children (perform CPU tasks, may be background thread)

RectContainsNode ( Rectangle rect ) : bool

Returns true if the given rectangle completely contains the terrain area that this node references.

RectIntersectsNode ( Rectangle rect ) : bool

Returns true if the given rectangle overlaps the terrain area that this node references.

ResetBounds ( Rectangle rect ) : void

Reset the bounds of this node and all its children for the region given.

TerrainQuadTreeNode ( Axiom.Components.Terrain.Terrain terrain, TerrainQuadTreeNode parent, ushort xOff, ushort yOff, ushort size, ushort lod, ushort depth, ushort quadrant ) : System

Default constructor.

Unload ( ) : void

Unload node and children (perform GPU tasks, will be render thread)

Unprepare ( ) : void

Unprepare node and children (perform CPU tasks, may be background thread)

UpdateRenderQueue ( RenderQueue queue ) : void

UpdateVertexData ( bool positions, bool deltas, Rectangle rect, bool cpuData ) : void

Tell the node to update its vertex data for a given region.

UseAncestorVertexData ( TerrainQuadTreeNode owner, int treeDepthEnd, int resolution ) : void

Tell a node that it should use an anscestor's vertex data.

VisitRenderables ( bool debugRenderables ) : void

Protected Methods

Method Description
CalcSkirtVertexIndex ( ushort mainIndex, bool isCol ) : ushort

CreateCpuIndexData ( ) : void

CreateCpuVertexData ( ) : void

CreateGpuIndexData ( ) : void

CreateGpuVertexData ( ) : void

CreateTriangleStripBuffer ( ushort batchSize, IndexData destData ) : void

DestroyCpuIndexData ( ) : void

DestroyCpuVertexData ( ) : void

DestroyGpuIndexData ( ) : void

DestroyGpuVertexData ( ) : void

UpdateGpuVertexData ( ) : void

UpdateVertexBuffer ( HardwareVertexBuffer posBuff, HardwareVertexBuffer deltaBuf, Rectangle rect ) : void

Private Methods

Method Description
UpdateVertexBufferr ( HardwareVertexBuffer posbuf, HardwareVertexBuffer deltabuf, Rectangle rect ) : void

Method Details

AssignVertexData() public method

Assign vertex data to the tree, from a depth and at a given resolution.
public AssignVertexData ( ushort treeDepthStart, ushort treeDepthEnd, ushort resolution, ushort sz ) : void
treeDepthStart ushort
treeDepthEnd ushort The end of the depth that should use this data (exclusive)
resolution ushort The resolution of the data to use (compared to full terrain)
sz ushort The size of the data along one edge
return void

CalcSkirtVertexIndex() protected method

protected CalcSkirtVertexIndex ( ushort mainIndex, bool isCol ) : ushort
mainIndex ushort
isCol bool
return ushort

CalculateCurrentLod() public method

Calculate appropriate LOD for this node and children
public CalculateCurrentLod ( Camera cam, float cFactor ) : bool
cam Axiom.Core.Camera The camera to be used (this should already be the LOD camera)
cFactor float The cFactor which incorporates the viewport size, max pixel error and lod bias
return bool

CreateCpuIndexData() protected method

protected CreateCpuIndexData ( ) : void
return void

CreateCpuVertexData() protected method

protected CreateCpuVertexData ( ) : void
return void

CreateGpuIndexData() protected method

protected CreateGpuIndexData ( ) : void
return void

CreateGpuVertexData() protected method

protected CreateGpuVertexData ( ) : void
return void

CreateTriangleStripBuffer() protected method

protected CreateTriangleStripBuffer ( ushort batchSize, IndexData destData ) : void
batchSize ushort
destData Axiom.Graphics.IndexData
return void

DestroyCpuIndexData() protected method

protected DestroyCpuIndexData ( ) : void
return void

DestroyCpuVertexData() protected method

protected DestroyCpuVertexData ( ) : void
return void

DestroyGpuIndexData() protected method

protected DestroyGpuIndexData ( ) : void
return void

DestroyGpuVertexData() protected method

protected DestroyGpuVertexData ( ) : void
return void

Dispose() public method

public Dispose ( ) : void
return void

FinaliseDeltaValues() public method

Promote the delta values calculated to the runtime ones (this must be called in the main thread).
public FinaliseDeltaValues ( Rectangle rect ) : void
rect Axiom.Core.Rectangle
return void

GetChild() public method

Get child node
public GetChild ( ushort child ) : TerrainQuadTreeNode
child ushort
return TerrainQuadTreeNode

GetLodLevel() public method

Get the LodLevel information for a given lod.
public GetLodLevel ( ushort lod ) : LodLevel
lod ushort /// The lod level index relative to this classes own list; if you /// want to use a global lod level, subtract getBaseLod() first. Higher /// LOD levels are lower detail. ///
return LodLevel

GetSquaredViewDepth() public method

public GetSquaredViewDepth ( Camera cam ) : float
cam Axiom.Core.Camera
return float

GetWorldTransforms() public method

public GetWorldTransforms ( Matrix4 xform ) : void
xform Axiom.Math.Matrix4
return void

Load() public method

Load node and children (perform GPU tasks, will be render thread)
public Load ( ) : void
return void

MergeIntoBounds() public method

Merge a point (relative to terrain node) into the local bounds, and that of children if applicable.
public MergeIntoBounds ( long x, long y, Vector3 pos ) : void
x long The point on the terrain to which this position corresponds /// (affects which nodes update their bounds)
y long The point on the terrain to which this position corresponds /// (affects which nodes update their bounds)
pos Vector3 The position relative to the terrain centre
return void

NotifyDelta() public method

Notify the node (and children) of a height delta value.
public NotifyDelta ( ushort x, ushort y, ushort lod, float delta ) : void
x ushort
y ushort
lod ushort
delta float
return void

PointIntersectsNode() public method

Returns true if the given point is in the terrain area that this node references.
public PointIntersectsNode ( long x, long y ) : bool
x long The point in top-level terrain coords
y long The point in top-level terrain coords
return bool

PostDeltaCalculation() public method

Notify the node (and children) that deltas are going to be calculated for a given range.
public PostDeltaCalculation ( Rectangle rect ) : void
rect Axiom.Core.Rectangle
return void

PreDeltaCalculation() public method

Notify the node (and children) that deltas are going to be calculated for a given range.
public PreDeltaCalculation ( Rectangle rect ) : void
rect Axiom.Core.Rectangle
return void

Prepare() public method

Prepare node and children (perform CPU tasks, may be background thread)
public Prepare ( ) : void
return void

RectContainsNode() public method

Returns true if the given rectangle completely contains the terrain area that this node references.
public RectContainsNode ( Rectangle rect ) : bool
rect Axiom.Core.Rectangle The region in top-level terrain coords
return bool

RectIntersectsNode() public method

Returns true if the given rectangle overlaps the terrain area that this node references.
public RectIntersectsNode ( Rectangle rect ) : bool
rect Axiom.Core.Rectangle The region in top-level terrain coords
return bool

ResetBounds() public method

Reset the bounds of this node and all its children for the region given.
public ResetBounds ( Rectangle rect ) : void
rect Axiom.Core.Rectangle The region for which bounds should be reset, in top-level terrain coords
return void

TerrainQuadTreeNode() public method

Default constructor.
public TerrainQuadTreeNode ( Axiom.Components.Terrain.Terrain terrain, TerrainQuadTreeNode parent, ushort xOff, ushort yOff, ushort size, ushort lod, ushort depth, ushort quadrant ) : System
terrain Axiom.Components.Terrain.Terrain The ultimate parent terrain
parent TerrainQuadTreeNode ptional parent node (in which case xoff, yoff are 0 and size must be entire terrain)
xOff ushort Offsets from the start of the terrain data in 2D
yOff ushort Offsets from the start of the terrain data in 2D
size ushort The size of the node in vertices at the highest LOD
lod ushort The base LOD level
depth ushort The depth that this node is at in the tree (or convenience)
quadrant ushort The index of the quadrant (0, 1, 2, 3)
return System

Unload() public method

Unload node and children (perform GPU tasks, will be render thread)
public Unload ( ) : void
return void

Unprepare() public method

Unprepare node and children (perform CPU tasks, may be background thread)
public Unprepare ( ) : void
return void

UpdateGpuVertexData() protected method

protected UpdateGpuVertexData ( ) : void
return void

UpdateRenderQueue() public method

public UpdateRenderQueue ( RenderQueue queue ) : void
queue Axiom.Graphics.RenderQueue
return void

UpdateVertexBuffer() protected method

protected UpdateVertexBuffer ( HardwareVertexBuffer posBuff, HardwareVertexBuffer deltaBuf, Rectangle rect ) : void
posBuff Axiom.Graphics.HardwareVertexBuffer
deltaBuf Axiom.Graphics.HardwareVertexBuffer
rect Axiom.Core.Rectangle
return void

UpdateVertexData() public method

Tell the node to update its vertex data for a given region.
public UpdateVertexData ( bool positions, bool deltas, Rectangle rect, bool cpuData ) : void
positions bool
deltas bool
rect Axiom.Core.Rectangle
cpuData bool
return void

UseAncestorVertexData() public method

Tell a node that it should use an anscestor's vertex data.
public UseAncestorVertexData ( TerrainQuadTreeNode owner, int treeDepthEnd, int resolution ) : void
owner TerrainQuadTreeNode
treeDepthEnd int The end of the depth that should use this data (exclusive)
resolution int The resolution of the data to use
return void

VisitRenderables() public method

public VisitRenderables ( bool debugRenderables ) : void
debugRenderables bool
return void

Property Details

DELTA_BUFFER public static property

Buffer binding used for holding delta values
public static short DELTA_BUFFER
return short

POSITION_BUFFER public static property

Buffer binding used for holding positions.
public static short POSITION_BUFFER
return short

mAABB protected property

relative to mLocalCentre
protected AxisAlignedBox,Axiom.Math mAABB
return Axiom.Math.AxisAlignedBox

mBaseLod protected property

protected ushort mBaseLod
return ushort

mBoundaryX protected property

protected ushort mBoundaryX
return ushort

mBoundaryY protected property

protected ushort mBoundaryY
return ushort

mBoundingRadius protected property

relative to mLocalCentre
protected float mBoundingRadius
return float

mChildWithMaxHeightDelta protected property

The child with the largest height delta
protected TerrainQuadTreeNode mChildWithMaxHeightDelta
return TerrainQuadTreeNode

mChildren protected property

protected TerrainQuadTreeNode[] mChildren
return TerrainQuadTreeNode[]

mCurrentLod protected property

-1 = none (do not render)
protected int mCurrentLod
return int

mDepth protected property

protected ushort mDepth
return ushort

mLocalCentre protected property

relative to terrain centre
protected Vector3 mLocalCentre
return Vector3

mLodLevels protected property

protected List mLodLevels
return List

mLodTransition protected property

// 0-1 transition to lower LOD
protected float mLodTransition
return float

mMaterialLodIndex protected property

protected ushort mMaterialLodIndex
return ushort

mNodeWithVertexData protected property

protected TerrainQuadTreeNode mNodeWithVertexData
return TerrainQuadTreeNode

mOffsetX protected property

protected ushort mOffsetX
return ushort

mOffsetY protected property

protected ushort mOffsetY
return ushort

mParent protected property

protected TerrainQuadTreeNode mParent
return TerrainQuadTreeNode

mQuadrant protected property

protected ushort mQuadrant
return ushort

mRend protected property

protected TerrainRendable mRend
return TerrainRendable

mSelfOrChildRendered protected property

protected bool mSelfOrChildRendered
return bool

mSize protected property

protected ushort mSize
return ushort

mTerrain protected property

protected Terrain mTerrain
return Terrain

mVertexDataRecord protected property

protected VertexDataRecord mVertexDataRecord
return VertexDataRecord