Search Results for

    Show / Hide Table of Contents

    Class TerrainPatch

    Represents single terrain patch made of 16 terrain chunks.

    Inheritance
    System.Object
    Object
    TerrainPatch
    Implements
    ISerializable
    Inherited Members
    Object.__unmanagedPtr
    Object.__internalId
    Object.Finalize()
    Object.As<T>()
    Object.NewValue(Type)
    Object.New(String)
    Object.Find<T>(Guid, Boolean)
    Object.Find(Guid, Type, Boolean)
    Object.TryFind<T>(Guid)
    Object.TryFind(Guid, Type)
    Object.Destroy(Object, Single)
    Object.DestroyNow(Object)
    Object.Destroy<T>(T, Single)
    Object.Equals(Object)
    Object.GetUnmanagedPtr(Object)
    Object.GetUnmanagedInterface(Object, Type)
    Object.FromUnmanagedPtr(IntPtr)
    Object.MapObjectID(Guid)
    Object.RemapObjectID(Guid)
    Object.GetHashCode()
    Object.ID
    Object.TypeName
    Namespace: FlaxEngine
    Assembly: FlaxEngine.CSharp.dll
    Syntax
    [Unmanaged]
    public sealed class TerrainPatch : Object, ISerializable

    Constructors

    TerrainPatch()

    Initializes a new instance of the TerrainPatch.

    Declaration
    public TerrainPatch()

    Properties

    Heightfield

    Gets the heightfield collision data asset.

    Declaration
    [Unmanaged]
    public RawDataAsset Heightfield { get; }
    Property Value
    RawDataAsset

    Heightmap

    The heightmap texture.

    Declaration
    [Unmanaged]
    public Texture Heightmap { get; set; }
    Property Value
    Texture

    Methods

    ClearCache()

    Clears all caches.

    Declaration
    [Unmanaged]
    public void ClearCache()

    ClearHeightmapCache()

    Clears cache of the heightmap data.

    Declaration
    [Unmanaged]
    public void ClearHeightmapCache()

    ClearHolesMaskCache()

    Clears cache of the holes mask data.

    Declaration
    [Unmanaged]
    public void ClearHolesMaskCache()

    ClearSplatMapCache()

    Clears cache of the splat map data.

    Declaration
    [Unmanaged]
    public void ClearSplatMapCache()

    ClosestPoint(ref Vector3, out Vector3)

    Gets a point on the terrain collider that is closest to a given location. Can be used to find a hit location or position to apply explosion force or any other special effects.

    Declaration
    [Unmanaged]
    public void ClosestPoint(ref Vector3 position, out Vector3 result)
    Parameters
    Vector3 position

    The position to find the closest point to it.

    Vector3 result

    The result point on the collider that is closest to the specified location.

    ExtractCollisionGeometry(out Float3[], out Int32[])

    Extracts the collision data geometry into list of triangles.

    Declaration
    [Unmanaged]
    public void ExtractCollisionGeometry(out Float3[] vertexBuffer, out int[] indexBuffer)
    Parameters
    Float3[] vertexBuffer

    The output vertex buffer.

    System.Int32[] indexBuffer

    The output index buffer.

    GetBounds()

    Gets the patch world bounds.

    Declaration
    [Unmanaged]
    public BoundingBox GetBounds()
    Returns
    BoundingBox

    GetChunk(ref Int2)

    Gets the chunk at the given location.

    Declaration
    [Unmanaged]
    public TerrainChunk GetChunk(ref Int2 chunkCoord)
    Parameters
    Int2 chunkCoord

    The chunk location (x and z).

    Returns
    TerrainChunk

    The chunk.

    GetChunk(Int32)

    Gets the chunk at the given index.

    Declaration
    [Unmanaged]
    public TerrainChunk GetChunk(int index)
    Parameters
    System.Int32 index

    The chunk zero-based index.

    Returns
    TerrainChunk

    The chunk.

    GetChunk(Int32, Int32)

    Gets the chunk at the given location.

    Declaration
    [Unmanaged]
    public TerrainChunk GetChunk(int x, int z)
    Parameters
    System.Int32 x

    The chunk location x.

    System.Int32 z

    The chunk location z.

    Returns
    TerrainChunk

    The chunk.

    GetHeightmapData()

    Gets the raw pointer to the heightmap data. Array size is square of Terrain.HeightmapSize.

    Declaration
    [Unmanaged]
    public float *GetHeightmapData()
    Returns
    System.Single*

    The heightmap data. Null if empty or failed to access it.

    GetHeightY()

    Gets the Y axis heightmap height.

    Declaration
    [Unmanaged]
    public float GetHeightY()
    Returns
    System.Single

    GetHolesMaskData()

    Gets the raw pointer to the holes mask data. Array size is square of Terrain.HeightmapSize.

    Declaration
    [Unmanaged]
    public byte *GetHolesMaskData()
    Returns
    System.Byte*

    The holes mask data. Null if empty/unused or failed to access it.

    GetOffsetY()

    Gets the Y axis heightmap offset from terrain origin.

    Declaration
    [Unmanaged]
    public float GetOffsetY()
    Returns
    System.Single

    GetSplatmap(Int32)

    Gets the splatmap assigned to this patch.

    Declaration
    [Unmanaged]
    public Texture GetSplatmap(int index)
    Parameters
    System.Int32 index

    The zero-based index of the splatmap.

    Returns
    Texture

    The splatmap texture.

    GetSplatMapData(Int32)

    Gets the raw pointer to the splat map data. Array size is square of Terrain.HeightmapSize.

    Declaration
    [Unmanaged]
    public Color32*GetSplatMapData(int index)
    Parameters
    System.Int32 index

    The zero-based index of the splatmap texture.

    Returns
    Color32*

    The splat map data. Null if empty/unused or failed to access it.

    GetTerrain()

    Gets the terrain.

    Declaration
    [Unmanaged]
    public Terrain GetTerrain()
    Returns
    Terrain

    GetX()

    Gets the x coordinate.

    Declaration
    [Unmanaged]
    public int GetX()
    Returns
    System.Int32

    GetZ()

    Gets the z coordinate.

    Declaration
    [Unmanaged]
    public int GetZ()
    Returns
    System.Int32

    InitializeHeightMap()

    Initializes the patch heightmap and collision to the default flat level.

    Declaration
    [Unmanaged]
    public bool InitializeHeightMap()
    Returns
    System.Boolean

    True if failed, otherwise false.

    ModifyHeightMap(Single*, Int2, Int2)

    Modifies the terrain patch heightmap with the given samples.

    Declaration
    [Unmanaged]
    public bool ModifyHeightMap(float *samples, Int2 modifiedOffset, Int2 modifiedSize)
    Parameters
    System.Single* samples

    The samples. The array length is size.X*size.Y.

    Int2 modifiedOffset

    The offset from the first row and column of the heightmap data (offset destination x and z start position).

    Int2 modifiedSize

    The size of the heightmap to modify (x and z). Amount of samples in each direction.

    Returns
    System.Boolean

    True if failed, otherwise false.

    ModifyHolesMask(Byte*, Int2, Int2)

    Modifies the terrain patch holes mask with the given samples.

    Declaration
    [Unmanaged]
    public bool ModifyHolesMask(byte *samples, Int2 modifiedOffset, Int2 modifiedSize)
    Parameters
    System.Byte* samples

    The samples. The array length is size.X*size.Y.

    Int2 modifiedOffset

    The offset from the first row and column of the holes map data (offset destination x and z start position).

    Int2 modifiedSize

    The size of the holes map to modify (x and z). Amount of samples in each direction.

    Returns
    System.Boolean

    True if failed, otherwise false.

    ModifySplatMap(Int32, Color32*, Int2, Int2)

    Modifies the terrain patch splat map (layers mask) with the given samples.

    Declaration
    [Unmanaged]
    public bool ModifySplatMap(int index, Color32*samples, Int2 modifiedOffset, Int2 modifiedSize)
    Parameters
    System.Int32 index

    The zero-based index of the splatmap texture.

    Color32* samples

    The samples. The array length is size.X*size.Y.

    Int2 modifiedOffset

    The offset from the first row and column of the splat map data (offset destination x and z start position).

    Int2 modifiedSize

    The size of the splat map to modify (x and z). Amount of samples in each direction.

    Returns
    System.Boolean

    True if failed, otherwise false.

    RayCast(Vector3, Vector3, out RayCastHit, Single)

    Performs a raycast against terrain collision, returns results in a RaycastHit structure.

    Declaration
    [Unmanaged]
    public bool RayCast(Vector3 origin, Vector3 direction, out RayCastHit hitInfo, float maxDistance = 3.40282347E+38F)
    Parameters
    Vector3 origin

    The origin of the ray.

    Vector3 direction

    The normalized direction of the ray.

    RayCastHit hitInfo

    The result hit information. Valid only when method returns true.

    System.Single maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    System.Boolean

    True if ray hits an object, otherwise false.

    RayCast(Vector3, Vector3, out Single, out TerrainChunk, Single)

    Performs a raycast against this terrain collision shape. Returns the hit chunk.

    Declaration
    [Unmanaged]
    public bool RayCast(Vector3 origin, Vector3 direction, out float resultHitDistance, out TerrainChunk resultChunk, float maxDistance = 3.40282347E+38F)
    Parameters
    Vector3 origin

    The origin of the ray.

    Vector3 direction

    The normalized direction of the ray.

    System.Single resultHitDistance

    The raycast result hit position distance from the ray origin. Valid only if raycast hits anything.

    TerrainChunk resultChunk

    The raycast result hit chunk. Valid only if raycast hits anything.

    System.Single maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    System.Boolean

    True if ray hits an object, otherwise false.

    RayCast(Vector3, Vector3, out Single, out Vector3, Single)

    Performs a raycast against this terrain collision shape.

    Declaration
    [Unmanaged]
    public bool RayCast(Vector3 origin, Vector3 direction, out float resultHitDistance, out Vector3 resultHitNormal, float maxDistance = 3.40282347E+38F)
    Parameters
    Vector3 origin

    The origin of the ray.

    Vector3 direction

    The normalized direction of the ray.

    System.Single resultHitDistance

    The raycast result hit position distance from the ray origin. Valid only if raycast hits anything.

    Vector3 resultHitNormal

    The raycast result hit position normal vector. Valid only if raycast hits anything.

    System.Single maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    System.Boolean

    True if ray hits an object, otherwise false.

    RayCast(Vector3, Vector3, out Single, Single)

    Performs a raycast against this terrain collision shape.

    Declaration
    [Unmanaged]
    public bool RayCast(Vector3 origin, Vector3 direction, out float resultHitDistance, float maxDistance = 3.40282347E+38F)
    Parameters
    Vector3 origin

    The origin of the ray.

    Vector3 direction

    The normalized direction of the ray.

    System.Single resultHitDistance

    The raycast result hit position distance from the ray origin. Valid only if raycast hits anything.

    System.Single maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    System.Boolean

    True if ray hits an object, otherwise false.

    SetSplatmap(Int32, Texture)

    Sets a splatmap to this patch.

    Declaration
    [Unmanaged]
    public void SetSplatmap(int index, Texture splatMap)
    Parameters
    System.Int32 index

    The zero-based index of the splatmap.

    Texture splatMap

    Splatmap texture.

    SetupHeightMap(Int32, Single*, Byte*, Boolean)

    Setups the terrain patch using the specified heightmap data.

    Declaration
    [Unmanaged]
    public bool SetupHeightMap(int heightMapLength, float *heightMap, byte *holesMask = default(byte *), bool forceUseVirtualStorage = false)
    Parameters
    System.Int32 heightMapLength

    The height map array length. It must match the terrain descriptor, so it should be (chunkSize*4+1)^2. Patch is a 4 by 4 square made of chunks. Each chunk has chunkSize quads on edge.

    System.Single* heightMap

    The height map. Each array item contains a height value.

    System.Byte* holesMask

    The holes mask (optional). Normalized to 0-1 range values with holes mask per-vertex. Must match the heightmap dimensions.

    System.Boolean forceUseVirtualStorage

    If set to true patch will use virtual storage by force. Otherwise it can use normal texture asset storage on drive (valid only during Editor). Runtime-created terrain can only use virtual storage (in RAM).

    Returns
    System.Boolean

    True if failed, otherwise false.

    SetupSplatMap(Int32, Int32, Color32*, Boolean)

    Setups the terrain patch layer weights using the specified splatmaps data.

    Declaration
    [Unmanaged]
    public bool SetupSplatMap(int index, int splatMapLength, Color32*splatMap, bool forceUseVirtualStorage = false)
    Parameters
    System.Int32 index

    The zero-based index of the splatmap texture.

    System.Int32 splatMapLength

    The splatmap map array length. It must match the terrain descriptor, so it should be (chunkSize*4+1)^2. Patch is a 4 by 4 square made of chunks. Each chunk has chunkSize quads on edge.

    Color32* splatMap

    The splat map. Each array item contains 4 layer weights.

    System.Boolean forceUseVirtualStorage

    If set to true patch will use virtual storage by force. Otherwise it can use normal texture asset storage on drive (valid only during Editor). Runtime-created terrain can only use virtual storage (in RAM).

    Returns
    System.Boolean

    True if failed, otherwise false.

    Extension Methods

    Extensions.ReflectiveCompare<T>(T, T)
    Extensions.DeepClone<T>(T)
    Extensions.RawClone<T>(T)
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat