Search Results for

    Show / Hide Table of Contents

    Class TerrainPatch

    Represents single terrain patch made of 16 terrain chunks.

    Inheritance
    Object
    ScriptingObject
    TerrainPatch
    Inherited Members
    ScriptingObject::_gcHandle
    ScriptingObject::_id
    ScriptingObject::_type
    ScriptingObject::CanCast(const ScriptingTypeHandle& from, const ScriptingTypeHandle& to)
    ScriptingObject::CanCast(const MClass* from, const MClass* to)
    ScriptingObject::Cast(ScriptingObject* obj)
    ScriptingObject::ChangeID(const Guid& newId)
    ScriptingObject::CreateManaged()
    ScriptingObject::CreateManagedInternal()
    ScriptingObject::Deleted
    Object::DeleteObject(float timeToLive = 0.0f, bool useGameTime=false)
    Object::DeleteObjectNow()
    ISerializable::DeserializeIfExists(DeserializeStream& stream, const char* memberName, ISerializeModifier* modifier)
    TerrainPatch
    ScriptingObject::DestroyManaged()
    Object::Flags
    ScriptingObject::FromInterface(void* interfaceObj, const ScriptingTypeHandle& interfaceType)
    ScriptingObject::FromInterface(T* interfaceObj)
    ScriptingObject::GetClass()
    ScriptingObject::GetID()
    ScriptingObject::GetManagedInstance()
    ScriptingObject::GetOrCreateManagedInstance()
    ScriptingObject::GetType()
    ScriptingObject::GetTypeHandle()
    ScriptingObject::HasManagedInstance()
    ScriptingObject::Is(const ScriptingTypeHandle& type)
    ScriptingObject::Is(const MClass* type)
    ScriptingObject::Is()
    ScriptingObject::IsRegistered()
    ScriptingObject::NewObject(const ScriptingTypeHandle& typeHandle)
    ScriptingObject::NewObject()
    ScriptingObject::OnDeleteObject()
    ScriptingObject::OnManagedInstanceDeleted()
    ScriptingObject::OnScriptingDispose()
    ScriptingObject::RegisterObject()
    ScriptingObject::ScriptingObject(const SpawnParams& params)
    TerrainPatch
    TerrainPatch
    ScriptingObject::SetManagedInstance(MObject* instance)
    TerrainPatch
    ScriptingObject::ToInterface(ScriptingObject* obj, const ScriptingTypeHandle& interfaceType)
    ScriptingObject::ToInterface(ScriptingObject* obj)
    ScriptingObject::ToManaged(const ScriptingObject* obj)
    ScriptingObject::ToNative(MObject* obj)
    ScriptingObject::ToString()
    ScriptingObject::UnregisterObject()
    ISerializable::~ISerializable()
    Object::~Object()
    ScriptingObject::~ScriptingObject()
    Assembly: FlaxEngine.dll
    File: Engine/Terrain/TerrainPatch.h
    Syntax
    public class TerrainPatch : public ScriptingObject, public ISerializable

    Constructors

    ~TerrainPatch()

    Finalizes an instance of the TerrainPatch class.

    Declaration
    public ~TerrainPatch()

    Fields

    Chunks

    The chunks contained within the patch. Organized in 4x4 square.

    Declaration
    public TerrainChunk Chunks[Terrain::ChunksCount]
    Field Value
    TerrainChunk

    Heightmap

    The heightmap texture.

    Declaration
    public AssetReference<Texture> Heightmap
    Field Value
    AssetReference<Texture>

    Splatmap

    The splatmap textures.

    Declaration
    public AssetReference<Texture> Splatmap[TERRAIN_MAX_SPLATMAPS_COUNT]
    Field Value
    AssetReference<Texture>

    Methods

    ClearCache()

    Clears all caches.

    Declaration
    public void ClearCache()

    ClearHeightmapCache()

    Clears cache of the heightmap data.

    Declaration
    public void ClearHeightmapCache()

    ClearHolesMaskCache()

    Clears cache of the holes mask data.

    Declaration
    public void ClearHolesMaskCache()

    ClearSplatMapCache()

    Clears cache of the splat map data.

    Declaration
    public void ClearSplatMapCache()

    ClosestPoint(const Vector3& position, Vector3& result)

    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
    public void ClosestPoint(const Vector3& position, Vector3& result) const
    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.

    Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)

    Deserializes object from the input stream.

    Declaration
    public virtual void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override
    Parameters
    DeserializeStream stream

    The input stream.

    ISerializeModifier modifier

    The deserialization modifier object. Always valid.

    Overrides
    ISerializable::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)

    ExtractCollisionGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer)

    Extracts the collision data geometry into list of triangles.

    Declaration
    public void ExtractCollisionGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer)
    Parameters
    Array<Float3> vertexBuffer

    The output vertex buffer.

    Array<int32> indexBuffer

    The output index buffer.

    GetBounds()

    Gets the patch world bounds.

    Declaration
    public BoundingBox GetBounds() const
    Returns
    BoundingBox

    GetChunk(const Int2& chunkCoord)

    Gets the chunk at the given location.

    Declaration
    public TerrainChunk* GetChunk(const Int2& chunkCoord)
    Parameters
    Int2 chunkCoord

    The chunk location (x and z).

    Returns
    TerrainChunk

    The chunk.

    GetChunk(int32 index)

    Gets the chunk at the given index.

    Declaration
    public TerrainChunk* GetChunk(int32 index)
    Parameters
    int32 index

    The chunk zero-based index.

    Returns
    TerrainChunk

    The chunk.

    GetChunk(int32 x, int32 z)

    Gets the chunk at the given location.

    Declaration
    public TerrainChunk* GetChunk(int32 x, int32 z)
    Parameters
    int32 x

    The chunk location x.

    int32 z

    The chunk location z.

    Returns
    TerrainChunk

    The chunk.

    GetCollisionTriangles()

    Gets the collision mesh triangles array (3 vertices per triangle in linear list). Cached internally to reuse data.

    Declaration
    public Array<Vector3> GetCollisionTriangles()
    Returns
    Array<Vector3>

    The collision triangles vertices list (in world-space).

    GetCollisionTriangles(const BoundingSphere& bounds, Array<Vector3>& result)

    Gets the collision mesh triangles array (3 vertices per triangle in linear list) that intersect with the given bounds.

    Declaration
    public void GetCollisionTriangles(const BoundingSphere& bounds, Array<Vector3>& result)
    Parameters
    BoundingSphere bounds

    The world-space bounds to find terrain triangles that intersect with it.

    Array<Vector3> result

    The result triangles that intersect with the given bounds (in world-space).

    GetHeightfield()

    Gets the heightfield collision data asset.

    Declaration
    public RawDataAsset* GetHeightfield() const
    Returns
    RawDataAsset

    The heightfield data asset.

    GetHeightmapData()

    Gets the raw pointer to the heightmap data.

    Declaration
    public float* GetHeightmapData()
    Returns
    float

    The heightmap data.

    GetHeightY()

    Gets the Y axis heightmap height.

    Declaration
    public float GetHeightY() const
    Returns
    float

    GetHolesMaskData()

    Gets the raw pointer to the holes mask data.

    Declaration
    public byte* GetHolesMaskData()
    Returns
    byte

    The holes mask data.

    GetOffsetY()

    Gets the Y axis heightmap offset from terrain origin.

    Declaration
    public float GetOffsetY() const
    Returns
    float

    GetSplatmap(int32 index)

    Gets the splatmap assigned to this patch.

    Declaration
    public AssetReference<Texture> GetSplatmap(int32 index)
    Parameters
    int32 index

    The zero-based index of the splatmap.

    Returns
    AssetReference<Texture>

    The splatmap texture.

    GetSplatMapData(int32 index)

    Gets the raw pointer to the splat map data.

    Declaration
    public Color32* GetSplatMapData(int32 index)
    Parameters
    int32 index

    The zero-based index of the splatmap texture.

    Returns
    Color32

    The splat map data.

    GetTerrain()

    Gets the terrain.

    Declaration
    public Terrain* GetTerrain() const
    Returns
    Terrain

    GetX()

    Gets the x coordinate.

    Declaration
    public int32 GetX() const
    Returns
    int32

    GetZ()

    Gets the z coordinate.

    Declaration
    public int32 GetZ() const
    Returns
    int32

    InitializeHeightMap()

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

    Declaration
    public bool InitializeHeightMap()
    Returns
    bool

    True if failed, otherwise false.

    ModifyHeightMap(const float* samples, const Int2& modifiedOffset, const Int2& modifiedSize)

    Modifies the terrain patch heightmap with the given samples.

    Declaration
    public bool ModifyHeightMap(const float* samples, const Int2& modifiedOffset, const Int2& modifiedSize)
    Parameters
    float 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
    bool

    True if failed, otherwise false.

    ModifyHolesMask(const byte* samples, const Int2& modifiedOffset, const Int2& modifiedSize)

    Modifies the terrain patch holes mask with the given samples.

    Declaration
    public bool ModifyHolesMask(const byte* samples, const Int2& modifiedOffset, const Int2& modifiedSize)
    Parameters
    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
    bool

    True if failed, otherwise false.

    ModifySplatMap(int32 index, const Color32* samples, const Int2& modifiedOffset, const Int2& modifiedSize)

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

    Declaration
    public bool ModifySplatMap(int32 index, const Color32* samples, const Int2& modifiedOffset, const Int2& modifiedSize)
    Parameters
    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
    bool

    True if failed, otherwise false.

    RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, float maxDistance=MAX_float)

    Performs a raycast against this terrain collision shape.

    Declaration
    public bool RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, float maxDistance=MAX_float) const
    Parameters
    Vector3 origin

    The origin of the ray.

    Vector3 direction

    The normalized direction of the ray.

    float resultHitDistance

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

    float maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    bool

    True if ray hits an object, otherwise false.

    RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, TerrainChunk*& resultChunk, float maxDistance=MAX_float)

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

    Declaration
    public bool RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, TerrainChunk*& resultChunk, float maxDistance=MAX_float) const
    Parameters
    Vector3 origin

    The origin of the ray.

    Vector3 direction

    The normalized direction of the ray.

    float 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.

    float maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    bool

    True if ray hits an object, otherwise false.

    RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, Vector3& resultHitNormal, float maxDistance=MAX_float)

    Performs a raycast against this terrain collision shape.

    Declaration
    public bool RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, Vector3& resultHitNormal, float maxDistance=MAX_float) const
    Parameters
    Vector3 origin

    The origin of the ray.

    Vector3 direction

    The normalized direction of the ray.

    float 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.

    float maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    bool

    True if ray hits an object, otherwise false.

    RayCast(const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, float maxDistance=MAX_float)

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

    Declaration
    public bool RayCast(const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, float maxDistance=MAX_float) const
    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.

    float maxDistance

    The maximum distance the ray should check for collisions.

    Returns
    bool

    True if ray hits an object, otherwise false.

    RemoveLightmap()

    Removes the lightmap data from the terrain patch.

    Declaration
    public void RemoveLightmap()

    Serialize(SerializeStream& stream, const void* otherObj)

    Serializes object to the output stream compared to the values of the other object instance (eg. default class object). If other object is null then serialize all properties.

    Declaration
    public virtual void Serialize(SerializeStream& stream, const void* otherObj) override
    Parameters
    SerializeStream stream

    The output stream.

    void otherObj

    The instance of the object to compare with and serialize only the modified properties. If null, then serialize all properties.

    Overrides
    ISerializable::Serialize(SerializeStream& stream, const void* otherObj)

    SetSplatmap(int32 index, const AssetReference<Texture>& splatMap)

    Sets a splatmap to this patch.

    Declaration
    public void SetSplatmap(int32 index, const AssetReference<Texture>& splatMap)
    Parameters
    int32 index

    The zero-based index of the splatmap.

    AssetReference<Texture> splatMap

    Splatmap texture.

    SetupHeightMap(int32 heightMapLength, const float* heightMap, const byte* holesMask=nullptr, bool forceUseVirtualStorage=false)

    Setups the terrain patch using the specified heightmap data.

    Declaration
    public bool SetupHeightMap(int32 heightMapLength, const float* heightMap, const byte* holesMask=nullptr, bool forceUseVirtualStorage=false)
    Parameters
    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.

    float heightMap

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

    byte holesMask

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

    bool 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
    bool

    True if failed, otherwise false.

    SetupSplatMap(int32 index, int32 splatMapLength, const Color32* splatMap, bool forceUseVirtualStorage=false)

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

    Declaration
    public bool SetupSplatMap(int32 index, int32 splatMapLength, const Color32* splatMap, bool forceUseVirtualStorage=false)
    Parameters
    int32 index

    The zero-based index of the splatmap texture.

    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.

    bool 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
    bool

    True if failed, otherwise false.

    UpdateBounds()

    Updates the cached bounds of the patch and child chunks.

    Declaration
    public void UpdateBounds()

    UpdatePostManualDeserialization()

    Updates the patch data after manual deserialization called at runtime (eg. by editor undo).

    Declaration
    public void UpdatePostManualDeserialization()

    UpdateTransform()

    Updates the cached transform of the patch and child chunks.

    Declaration
    public void UpdateTransform()
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat