Unigine.WorldClutter Class
Inherits from: | Node |
WorldClutter class allows to randomly position reference nodes according to the mask and using the specified seed. For each node a probability of appearing is set. All nodes in the world clutter are rendered visible only within a specified distance and then fade out. Just like the ObjectGrass, world clutter is rendered in cells.
There are two benefits of using WorldClutter:
- Instances of nodes that are currently outside the view frustum are not stored in the memory, which provides much more efficient memory usage.
- Less cluttered spatial tree, which allows, for example, faster collision detection.
You can use a mask to cut out clutter objects in the areas of intersection with other objects and decals (e.g. to remove vegetation under houses or from the surface of roads projected using decals).
See Also#
A UnigineScript API sample <UnigineSDK>/data/samples/worlds/clutter_00
WorldClutter Class
Properties
int CutoutInverse#
int CutoutIntersectionMask#
- for decals use getIntersectionMask()
- for objects use getIntersectionMask()
int MaskInverse#
int MaskMaxValue#
int MaskMinValue#
int MaskFlipY#
int MaskFlipX#
float Angle#
float Threshold#
float Density#
float Step#
float SizeY#
float SizeX#
int Seed#
int SpawnRate#
float FadeDistance#
float VisibleDistance#
int Intersection#
int Orientation#
int NumReferences#
Members
WorldClutter ( ) #
Constructor. Creates a world clutter with default properties.void Invalidate ( ) #
Invalidates all world clutter cells. All invalidated cells will be regenerated.void Invalidate ( WorldBoundBox bounds ) #
Invalidates all world clutter cells within the area specified by the given bounding box. All invalidated cells will be regenerated.Arguments
- WorldBoundBox bounds - Bounding box, defining the area, where world clutter cells will be regenerated.
int SetMaskImage ( Image image, bool invalidate = 1 ) #
Sets an image (in R8 format) that defines the placement of meshes.Arguments
- Image image - Pointer to the image.
- bool invalidate - Invalidate flag. Set true to invalidate all world clutter cells; otherwise, set false. All invalidated cells will be regenerated.
Return value
1 if the mask image is successfully set; otherwise, 0.int GetMaskImage ( Image image ) #
Writes the image that is currently used as a mask for the placement of meshes into the given buffer.Arguments
- Image image - Image buffer to store a mask into.
Return value
1 if the mask image is successfully written into the buffer; otherwise, 0.void SetMaskImageName ( string image_name, bool invalidate = 1 ) #
Sets the name of a new mask image (in R8 format) that defines the placement of meshes.Arguments
- string image_name - Name (path) of the mask image.
- bool invalidate - Invalidate flag. Set true to invalidate all world clutter cells; otherwise, set false. All invalidated cells will be regenerated.
string GetMaskImageName ( ) #
Returns the name of a mask image (in R8 format) that defines the placement of reference nodes.Return value
Name (path) of the mask image.int SetMaskMesh ( Mesh mesh, bool invalidate = 1 ) #
Sets a mesh to be used as a mask on-the-fly. Limitations:- Before the method is called, another mesh must be set via setMaskMeshName() first.
- If the world is reloaded, the mesh set via setMaskMeshName() will be loaded.
- If the memory limit is exceeded, the new mesh might be replaced with the mesh set via setMaskMeshName().
Arguments
- Mesh mesh - Mesh instance.
- bool invalidate - Invalidate flag. Set true to invalidate all world clutter cells; otherwise, set false. All invalidated cells will be regenerated.
Return value
1 if the mesh is set successfully; otherwise - 0.int GetMaskMesh ( Mesh mesh ) #
Copies the current mask mesh (if it exists) to the specified target mesh.Arguments
- Mesh mesh - Mesh instance to copy the current mask mesh to.
Return value
1 if mesh mask exists; otherwise - 0.void SetMaskMeshName ( string mesh_name, bool invalidate = 1 ) #
Sets a mesh to be used as a mask for the world clutter. This mesh should be plane.Arguments
- string mesh_name - Path to the *.mesh file.
- bool invalidate - Invalidate flag. Set true to invalidate all world clutter cells; otherwise, set false. All invalidated cells will be regenerated.
string GetMaskMeshName ( ) #
Returns the name (path) of the current mesh used as a mask for the world clutter. This mesh should be plane.Return value
Path to the *.mesh file.void SetMaxScale ( float mean, float spread ) #
Sets the scale for meshes in the areas with high density (according to the mask). With the minimum scale it is possible to automatically render, for example, big trees in the center of the forest. A spread value enables to control the range of scales relative to the mean value.Arguments
- float mean - Scale mean value.
- float spread - Maximum spread value to randomly upscale or downscale objects.
float GetMaxScaleMean ( ) #
Returns the scale mean value for meshes in the areas with high density (according to the mask).Return value
Scale mean value.float GetMaxScaleSpread ( ) #
Returns the scale spread value that controls the range of mesh scales in the areas with high density (according to the mask).Return value
Scale spread value.void SetMinScale ( float mean, float spread ) #
Sets the scale for meshes in the areas with low density (according to the mask). With the minimum scale it is possible to automatically render, for example, small trees at the forest border. A spread value allows to control the range of scales relative to the mean value.Arguments
- float mean - Scale mean value.
- float spread - Maximum spread value to randomly upscale or downscale objects.
float GetMinScaleMean ( ) #
Returns the scale mean value for meshes in the areas with low density (according to the mask).Return value
Scale mean value.float GetMinScaleSpread ( ) #
Returns the scale spread value that controls the range of mesh scales in the areas with low density (according to the mask).Return value
Scale spread value.void SetNodesRotation ( vec3 mean, vec3 spread ) #
Sets the rotation of reference nodes along X, Y and Z axes.Arguments
- vec3 mean - Mean values of rotation angles in degrees.
- vec3 spread - Spread values of rotation angles in degrees.
vec3 GetNodesRotationMean ( ) #
Returns the mean value of reference nodes rotation along X, Y and Z axes.Return value
Mean values of rotation angles in degrees.vec3 GetNodesRotationSpread ( ) #
Returns the spread value of reference nodes rotation along X, Y and Z axes.Return value
Spread values of rotation angles in degrees.void SetOffset ( float mean, float spread ) #
Sets the vertical offset that determines the placement of reference nodes above or below the surface.Arguments
- float mean - Mean value of the offset in units.
- float spread - Spread value of the offset in units.
float GetOffsetMean ( ) #
Returns the current mean value of the vertical offset that determines the placement of reference nodes above or below the surface.Return value
Mean value of the offset in units.float GetOffsetSpread ( ) #
Returns the current spread value of the vertical offset that determines the placement of reference nodes above or below the surface.Return value
Spread value of the offset in units.void SetReferenceName ( int num, string name ) #
Sets the name of the specified reference node contained in the world clutter.Arguments
- int num - The number of the reference node.
- string name - Name to be updated.
string GetReferenceName ( int num ) #
Returns the name of the reference node contained in the world clutter.Arguments
- int num - The number of the reference node among contained in the world clutter.
Return value
Name of the reference node.void SetReferenceProbability ( int num, float probability ) #
Sets the probability of the occurrence of the specified node reference.Arguments
- int num - The number of the reference node.
- float probability - Probability factor. The provided value is saturated in range [0;1].
float GetReferenceProbability ( int num ) #
Returns the probability of the occurrence of the specified node reference.Arguments
- int num - The number of the reference node.
Return value
Probability factor.int AddReference ( string name ) #
Adds a new reference node to the world clutter.Arguments
- string name - Name of the reference node.
Return value
The number of added reference node.void RemoveReference ( int num ) #
Removes the specified reference node from the world clutter.Arguments
- int num - The number of the reference node.
static int type ( ) #
Returns the type of the node.Return value
World type identifier.void ClearReferences ( ) #
Deletes all reference nodes from the world clutter.bool SaveStateReferences ( Stream stream ) #
Saves the state of all reference nodes from the world clutter to the specified stream.Example using saveStateReferences() and restoreStateReferences() methods:
// initialize a node and set its state
WorldClutter worldClutter = new WorldClutter();
worldClutter.SizeX = 500.0f;
worldClutter.SizeY = 500.0f;
// save state
Blob blob_state = new Blob();
worldClutter.SaveStateReferences(blob_state);
// change the node state
worldClutter.SizeY = 700.0f;
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
worldClutter.RestoreStateReferences(blob_state);
Arguments
- Stream stream - Stream instance.
Return value
true if the states of all reference nodes from the world clutter were successfully saved to the specified stream; otherwise, false.bool RestoreStateReferences ( Stream stream ) #
Restores the state of all reference nodes from the world clutter from the specified stream.Example using saveStateReferences() and restoreStateReferences() methods:
// initialize a node and set its state
WorldClutter worldClutter = new WorldClutter();
worldClutter.SizeX = 500.0f;
worldClutter.SizeY = 500.0f;
// save state
Blob blob_state = new Blob();
worldClutter.SaveStateReferences(blob_state);
// change the node state
worldClutter.SizeY = 700.0f;
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
worldClutter.RestoreStateReferences(blob_state);
Arguments
- Stream stream - Stream instance.