Class Foliage
Represents a foliage actor that contains a set of instanced meshes.
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public sealed class Foliage : Actor, ISerializable
Constructors
Foliage()
Properties
FoliageTypesCount
Gets the total amount of the types of foliage.
Declaration
[Unmanaged]
public int FoliageTypesCount { get; }
Property Value
System.Int32
|
GlobalDensityScale
Gets or sets the global density scale for all foliage instances. The default value is 1. Use values from range 0-1. Lower values decrease amount of foliage instances in-game. Use it to tweak game performance for slower devices.
Declaration
[Unmanaged]
public static float GlobalDensityScale { get; set; }
Property Value
System.Single
|
InstancesCount
Gets the total amount of the instanced of foliage.
Declaration
[Unmanaged]
public int InstancesCount { get; }
Property Value
System.Int32
|
Methods
AddFoliageType(Model)
Adds the type of the foliage.
Declaration
[Unmanaged]
public void AddFoliageType(Model model)
Parameters
Model
model
The model to assign. It cannot be null nor already used by the other instance type (it must be unique within the given foliage actor). |
AddInstance(ref FoliageInstance)
Adds the new foliage instance. Ensure to always call RebuildClusters() after editing foliage to sync cached data (call it once after editing one or more instances).
Declaration
[Unmanaged]
public void AddInstance(ref FoliageInstance instance)
Parameters
FoliageInstance
instance
The instance. |
Remarks
Input instance bounds, instance random and world matrix are ignored (recalculated).
GetFoliageType(Int32)
Gets the foliage type.
Declaration
[Unmanaged]
public FoliageType GetFoliageType(int index)
Parameters
System.Int32
index
The zero-based index of the foliage type. |
Returns
FoliageType
The foliage type. |
GetFoliageTypeInstancesCount(Int32)
Gets the total amount of the instanced that use the given foliage type.
Declaration
[Unmanaged]
public int GetFoliageTypeInstancesCount(int index)
Parameters
System.Int32
index
The zero-based index of the foliage type. |
Returns
System.Int32
The foliage type instances count. |
GetInstance(Int32)
Gets the foliage instance by index.
Declaration
[Unmanaged]
public FoliageInstance GetInstance(int index)
Parameters
System.Int32
index
The zero-based index of the foliage instance. |
Returns
FoliageInstance
The foliage instance data. |
Intersects(ref Ray, out Single, out Vector3, out Int32)
Determines if there is an intersection between the current object or any it's child and a ray.
Declaration
[Unmanaged]
public bool Intersects(ref Ray ray, out float distance, out Vector3 normal, out int instanceIndex)
Parameters
Ray
ray
The ray to test. |
System.Single
distance
When the method completes, contains the distance of the intersection (if any valid). |
Vector3
normal
When the method completes, contains the intersection surface normal vector (if any valid). |
System.Int32
instanceIndex
When the method completes, contains zero-based index of the foliage instance that is the closest to the ray. |
Returns
System.Boolean
True whether the two objects intersected, otherwise false. |
RebuildClusters()
Rebuilds the foliage clusters used as internal acceleration structures (quad tree).
Declaration
[Unmanaged]
public void RebuildClusters()
RemoveAllInstances()
Clears all foliage instances. Preserves the foliage types and other properties.
Declaration
[Unmanaged]
public void RemoveAllInstances()
RemoveFoliageType(Int32)
Removes the foliage instance type and all foliage instances using this type.
Declaration
[Unmanaged]
public void RemoveFoliageType(int index)
Parameters
System.Int32
index
The zero-based index of the foliage instance type. |
RemoveInstance(Int32)
Removes the foliage instance. Ensure to always call RebuildClusters() after editing foliage to sync cached data (call it once after editing one or more instances).
Declaration
[Unmanaged]
public void RemoveInstance(int index)
Parameters
System.Int32
index
The zero-based index of the instance to remove. |
SetInstanceTransform(Int32, ref Transform)
Sets the foliage instance transformation. Ensure to always call RebuildClusters() after editing foliage to sync cached data (call it once after editing one or more instances).
Declaration
[Unmanaged]
public void SetInstanceTransform(int index, ref Transform value)
Parameters
System.Int32
index
The zero-based index of the foliage instance. |
Transform
value
The value. |
UpdateCullDistance()
Updates the cull distance for all foliage instances and for created clusters.
Declaration
[Unmanaged]
public void UpdateCullDistance()