MeshTree

Description

sealed class Tinman.Terrain.Kernel.MeshTree

This interface provides quad-tree like access to the structure of a CLOD mesh.

The structure of a CLOD mesh is a directed acyclic graph of vertices and links and can be interpreted as a quadtree. The MeshTree interface provides access to this quadtree.

The MeshTree object of a CLOD IMesh can be used to implement hierarchical traversal algorithms, such as frustum culling, picking and collision detection.

Each face of a mesh represents the root node of a quadtree (see GetRoot). The GetChild* methods can be used to traverse the quadtree hierarchy. A quadtree node is equivalent to a mesh sector which is referred to using the index of its center vertex. So the vertex index values using with this class can also be used to access vertex data arrays.

The following figures illustrates the concept of parent/child sectors and parent index values:

    Pidx(S) = 3               Pidx(S) = 2
+--------+--------+       +--------+--------+
|        |        |       |        |        |
|  C(3)  |  C(2)  |       |  (C0)  |  (C3)  |
|        |        |       |        |        |
+-------(S)-------+       +-------(S)-------+
|        |        |       |        |        |
|  C(0)  |  C(1)  |       |  (C1)  |  (C2)  |
|        |        |       |        |        |
+--------+-------(P)     (P)-------+--------+

    Pidx(S) = 0               Pidx(S) = 1
+--------+-------(P)     (P)-------+--------+
|        |        |       |        |        |
|  (C2)  |  (C1)  |       |  (C1)  |  (C0)  |
|        |        |       |        |        |
+-------(S)-------+       +-------(S)-------+
|        |        |       |        |        |
|  (C3)  |  (C0)  |       |  (C2)  |  (C3)  |
|        |        |       |        |        |
+--------+--------+       +--------+--------+

C(0) := S.LL.LL = S.L[L.L]L = S.LLL = S.L[L]L => LL = 0
C(1) := S.LL.LR = S.L[L.L]R = S.LLR = S.L[L]R => LR = 1
C(2) := S.RL.LL = S.R[L.L]L = S.RLL = S.R[L]L => RL = 2
C(3) := S.RL.LR = S.R[L.L]R = S.RLR = S.R[L]R => RR = 3

where (P) is the center vertex of the parent sector, (S) is the center vertex of the current sector, C(n) is the center vertex of the n-th child vertex with n being the child index and Pidx(S) is the child index of (S) in (P).

See also

XDag

Public / Methods

Compute​Sector​Hash

2 overloads


[Pure]
public method ComputeSectorHash1 → ()

returns → int32

The hash value.

Computes a hash value that represents the mesh structure.


[Pure]
public method ComputeSectorHash2 → (2)

sector in : int32

The mesh sector.

hash opt : int32 = 0

The input hash value.

returns → int32

The output hash value.

Computes a hash value that represents the mesh structure of the given sector.

Filter


public method Filter → (2)

filterIn in : MeshTreeFilter

Optional input filter to use.

filterOut opt : MeshTreeFilter = null

Optional output filter to use.

returns → MeshTree

The resulting MeshTree object.

Returns an MeshTree object which represents the mesh structure filtered by the given filter.

Specifying the same MeshTreeFilter instance multiple times will result in a single filtered MeshTree instance. A MeshTreeFilter object must only be used with one MeshTree object.

Get​Child


[Pure]
public method GetChild → (2)

sector in : int32

The mesh sector.

child in : int32

Index of child sector in the range [0..3].

returns → int32

Index of child sector center or XDag.Null if the child sector does not exist or XDag.Void if the child sector resp. sector quadrant has been culled away.

Returns a child of the given mesh sector.

Get​Corners


[Pure]
public method GetCorners → (1)

sector in : int32

The mesh sector.

returns → Vec4I

The four corner vertices of the mesh sector.

Returns the four corner vertices of the given sector.

The returned vector has the following meaning:

Get​Down


[Pure]
public method GetDown → (2)

vertex in : int32

The mesh vertex.

link in : int32

One of XDag.LL, XDag.LR, XDag.RL and XDag.RR.

returns → int32

Index of linked vertex or XDag.Null if the vertex does not exist or XDag.Void if the vertex has been culled away.

Returns a downwards vertex link.

Get​Down​Force


[Pure]
public method GetDownForce → (2)

sector in : int32

Index of mesh sector center.

link in : int32

One of XDag.LL, XDag.LR, XDag.RL and XDag.RR.

returns → int32

Index of linked vertex or XDag.Void if the vertex does not exist.

Returns a downwards vertex link.

Get​Index


[Pure]
public method GetIndex → (1)

sector in : int32

The mesh sector.

returns → int32

Child index of sector in in its parent sector.

Returns the child index of the given sector in its parent sector.

Get​Orientation


[Pure]
public static method GetOrientation → (3)

corners in : Vec4I

The mesh sector corners (see GetCorners).

heightmapCoords in : Int3

The heightmap coordinates (see Semantic.HeightmapCoords).

face opt : CubemapFace = CubemapFace.NegZ

The cubemap face.

returns → int32

The orientation code (see remarks).

Returns the orientation of the given mesh sector.

The orientation of the mesh sector is computed relative to the face coordinates of the cubemap coordinates of its corner vertices:

o--> face X-coordinates
|
V face Y-coordinates

#0:   #1:   #2:   #3:   #4:   #5:   #6:   #7:
A R   A L   L G   R G   R A   L A   G L   G R
L G   R G   A R   A L   G L   G R   R A   L A

0x1 := diagonal flip (along line from A to G)?
0x2 := vertical flip?
0x4 := horizontal flip?

where A, R, L and G represent the corner vertices of the mesh sector, specified via corners in.

Get​Parent


[Pure]
public method GetParent → (1)

sector in : int32

The mesh sector.

returns → int32

The parent sector or XDag.Null if not existent.

Returns the parent sector for the given mesh sector.

Get​Root


[Pure]
public method GetRoot → (1)

face in : CubemapFace

The mesh face.

returns → int32

Index of root sector center vertex or XDag.Null.

Returns the root sector of the given mesh face.

Get​Up


[Pure]
public method GetUp → (2)

vertex in : int32

The mesh vertex.

link in : int32

One of XDag.L, XDag.R, XDag.G and XDag.A.

returns → int32

Index of linked vertex or XDag.Null if the vertex does not exist.

Returns an upwards vertex link.

Has​Mark


public method HasMark → (1)

sector in : int32

The mesh sector.

returns → bool

true if the sector is marked, false if not.

Checks if the given mesh sector has a mark, either implicit, explicit or both.

See also

MeshTreeFilter

Has​Mark​Explicit


public method HasMarkExplicit → (1)

sector in : int32

The mesh sector.

returns → bool

true if the sector is marked explicitly, false if not.

Checks if the given mesh sector has an explicit mark.

Mesh sectors receive explicit marks only from the SectorMark method.

See also

MeshTreeFilter

Has​Mark​Implicit


public method HasMarkImplicit → (1)

sector in : int32

The mesh sector.

returns → bool

true if the sector is marked implicitly, false if not.

Checks if the given mesh sector has an implicit mark.

A mesh sector receives an implicit mark when one of its descendants is marked explicitly.

See also

MeshTreeFilter

Is​Even


[Pure]
public method IsEven → (1)

vertex in : int32

The mesh sector.

returns → bool

true if the mesh sector is 'even', false if it is 'odd'.

Is the given mesh sector 'even' (see XDag)?

Is​Solid


public method IsSolid → (1)

sector in : int32

The mesh sector.

returns → bool

true if the sector is solid, false if not.

Checks if the given mesh sector is solid, i.e. if none of its descendants have been culled away.

Sector​Cull


public method SectorCull → (2)

sector in : int32

Index of mesh sector center.

quadrantMask opt : int32 = 15

The sector quadrants to cull. Set to 0xF to cull the whole sector.

Culls the given mesh sector by adding cull flags to the output filter of this mesh tree.

When culling a mesh sector, its marks (both explicit and implicit) will be retained.

Sector​Cull​Add


public method SectorCullAdd → (1)

filter in : MeshTreeFilter

[not-null]
The mesh filter.

Computes the union of the cull flags (see SectorCull) in the input filter of this mesh tree and the given mesh filter, storing the result back into the input filter.

If this mesh tree does not have an input filter, the method silently returns.

Sector​Cull​Retain


public method SectorCullRetain → (1)

filter in : MeshTreeFilter

[not-null]
The mesh filter.

Computes the intersection of the cull flags (see SectorCull) in the input filter of this mesh tree and the given mesh filter, storing the result back into the input filter.

If this mesh tree does not have an input filter, the method silently returns.

Sector​Mark


public method SectorMark → (1)

sector in : int32

Index of mesh sector center vertex.

Marks the given mesh sector by adding mark flags to the output filter of this mesh tree.

Mesh sectors can receive marks (both explicit or implicit) even if they have been culled away earlier.

See also

MeshTreeFilter

Sector​Mark​Add


public method SectorMarkAdd → (1)

filter in : MeshTreeFilter

[not-null]
The mesh filter.

Computes the union of the mark flags (see SectorMark) in the input filter of this mesh tree and the given mesh filter, storing the result back into the input filter.

If this mesh tree does not have an input filter, the method silently returns.

Sector​Mark​Roots


public method SectorMarkRoots → ()

Marks the root sectors of the mesh by adding mark flags to the output filter of this mesh tree.