Class Foliage
Represents a foliage actor that contains a set of instanced meshes.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Foliage/Foliage.h
Syntax
public class Foliage : public Actor
Fields
FoliageTypes
The foliage instances types used by the current foliage actor. It's read-only.
Declaration
public Array<FoliageType> FoliageTypes
Field Value
Array<FoliageType>
|
Instances
The allocated foliage instances. It's read-only.
Declaration
public ChunkedArray<FoliageInstance, FOLIAGE_INSTANCE_CHUNKS_SIZE> Instances
Field Value
ChunkedArray<FoliageInstance, FOLIAGE_INSTANCE_CHUNKS_SIZE>
|
Methods
AddFoliageType(Model* model)
Adds the type of the foliage.
Declaration
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(const FoliageInstance& instance)
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).
Input instance bounds, instance random and world matrix are ignored (recalculated).
Declaration
public void AddInstance(const FoliageInstance& instance)
Parameters
FoliageInstance
instance
The instance. |
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
Draw(RenderContext& renderContext)
Draws this actor. Called by Scene Rendering service. This call is more optimized than generic Draw (eg. geometry is rendered during all pass types but other actors are drawn only during GBufferFill pass).
Declaration
public virtual void Draw(RenderContext& renderContext) override
Parameters
RenderContext
renderContext
The rendering context. |
Overrides
Draw(RenderContextBatch& renderContextBatch)
Draws this actor. Called by Scene Rendering service. This call is more optimized than generic Draw (eg. geometry is rendered during all pass types but other actors are drawn only during GBufferFill pass).
Declaration
public virtual void Draw(RenderContextBatch& renderContextBatch) override
Parameters
RenderContextBatch
renderContextBatch
The rendering context batch (eg, main view and shadow projections). |
Overrides
GetFoliageType(int32 index)
Gets the foliage type.
Declaration
public FoliageType* GetFoliageType(int32 index)
Parameters
int32
index
The zero-based index of the foliage type. |
Returns
FoliageType
The foliage type. |
GetFoliageTypeInstancesCount(int32 index)
Gets the total amount of the instanced that use the given foliage type.
Declaration
public int32 GetFoliageTypeInstancesCount(int32 index) const
Parameters
int32
index
The zero-based index of the foliage type. |
Returns
int32
The foliage type instances count. |
GetFoliageTypesCount()
Gets the total amount of the types of foliage.
Declaration
public int32 GetFoliageTypesCount() const
Returns
int32
The foliage types count. |
GetGlobalDensityScale()
Gets 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
public static float GetGlobalDensityScale()
Returns
float
|
GetInstance(int32 index)
Gets the foliage instance by index.
Declaration
public FoliageInstance GetInstance(int32 index) const
Parameters
int32
index
The zero-based index of the foliage instance. |
Returns
FoliageInstance
The foliage instance data. |
GetInstancesCount()
Gets the total amount of the instanced of foliage.
Declaration
public int32 GetInstancesCount() const
Returns
int32
The foliage instances count. |
Intersects(const Ray& ray, Real& distance, Vector3& normal, int32& instanceIndex)
Determines if there is an intersection between the current object or any it's child and a ray.
Declaration
public bool Intersects(const Ray& ray, Real& distance, Vector3& normal, int32& instanceIndex)
Parameters
Ray
ray
The ray to test. |
Real
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). |
int32
instanceIndex
When the method completes, contains zero-based index of the foliage instance that is the closest to the ray. |
Returns
bool
True whether the two objects intersected, otherwise false. |
IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)
Determines if there is an intersection between the current object and a ray.
Declaration
public virtual bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override
Parameters
Ray
ray
The ray to test. |
Real
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). |
Returns
bool
True whether the two objects intersected, otherwise false. |
Overrides
OnDisable()
Called when actor gets removed from game systems. Occurs on EndPlay event or when actor gets inactivated in hierarchy. Use this event to unregister object from other game system (eg. audio).
Declaration
protected virtual void OnDisable() override
Overrides
OnEnable()
Called when actor gets added to game systems. Occurs on BeginPlay event or when actor gets activated in hierarchy. Use this event to register object to other game system (eg. audio).
Declaration
protected virtual void OnEnable() override
Overrides
OnFoliageTypeModelLoaded(int32 index)
Called when foliage type model is loaded.
Declaration
public void OnFoliageTypeModelLoaded(int32 index)
Parameters
int32
index
The zero-based index of the foliage type. |
OnLayerChanged()
Called when layer gets changed.
Declaration
public virtual void OnLayerChanged() override
Overrides
OnTransformChanged()
Called when actor transform gets changed.
Declaration
protected virtual void OnTransformChanged() override
Overrides
RebuildClusters()
Rebuilds the foliage clusters used as internal acceleration structures (quad tree).
Declaration
public void RebuildClusters()
RemoveAllInstances()
Clears all foliage instances. Preserves the foliage types and other properties.
Declaration
public void RemoveAllInstances()
RemoveFoliageType(int32 index)
Removes the foliage instance type and all foliage instances using this type.
Declaration
public void RemoveFoliageType(int32 index)
Parameters
int32
index
The zero-based index of the foliage instance type. |
RemoveInstance(ChunkedArray<FoliageInstance, FOLIAGE_INSTANCE_CHUNKS_SIZE>::Iterator i)
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
public void RemoveInstance(ChunkedArray<FoliageInstance, FOLIAGE_INSTANCE_CHUNKS_SIZE>::Iterator i)
Parameters
ChunkedArray<FoliageInstance, FOLIAGE_INSTANCE_CHUNKS_SIZE>::Iterator
i
The iterator from foliage instances that points to the instance to remove. |
RemoveInstance(int32 index)
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
public void RemoveInstance(int32 index)
Parameters
int32
index
The zero-based index of the instance to remove. |
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
SetGlobalDensityScale(float value)
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
public static void SetGlobalDensityScale(float value)
Parameters
float
value
|
SetInstanceTransform(int32 index, const Transform& value)
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
public void SetInstanceTransform(int32 index, const Transform& value)
Parameters
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
public void UpdateCullDistance()