LandscapeFetch Class
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.
This class is used to fetch data of the Landscape Terrain Object at a certain point (e.g. a height request) or check for an intersection with a traced line. The following performance optimizations are available:
- For each request you can engage or disengage certain data types (albedo, heights, masks, etc.). When the data type is engaged, you can obtain information via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point).
- Both fetch and intersection requests can be performed asynchronously when an instant result is not required.
The workflow is as follows:
- Create a new LandscapeFetch object instance.
- Set necessary parameters (e.g. which data layers are to be used, whether to enable holes or not, etc.).
- To get terrain data for a certain point call the fetchForce() method providing coordinates for the desired point.You can also fetch terrain data asynchronously via the fetchAsync() method.
- To find an intersection of a traced line with the terrain call either the intersectionForce() method or the intersectionAsync() method, if you want to perform an asynchronous request.
Usage Example#
// creating a fetch object and setting necessary parameters
LandscapeFetchPtr landscape_fetch = LandscapeFetch::create();
landscape_fetch->setUses(0);
landscape_fetch->setUsesHeight(true);
landscape_fetch->setHolesEnabled(true);
// ...
// getting terrain data for a point at (100, 100) and printing the height value
landscape_fetch->setFetchPosition(Vec2(100, 100));
if (landscape_fetch->fetchForce())
Log::message("Terrain height at the specified point is: %f", Scalar(landscape_fetch->getHeight()));
Asynchronous Operations Example#
// creating a fetch object and setting necessary parameters
LandscapeFetchPtr landscape_fetch = LandscapeFetch::create();
landscape_fetch->setUses(0);
landscape_fetch->setUsesHeight(true);
landscape_fetch->setHolesEnabled(true);
// ...
// making an asynchronous fetch request for a point at (2.05, 2.05)
landscape_fetch->setFetchPosition(Vec2(2.05f, 2.05f));
landscape_fetch->fetchAsync();
// ...
// checking if our asynchronous fetch request is completed and printing the height value
if (landscape_fetch->isAsyncCompleted()) {
Log::message("Terrain height at the specified point is: %f", Scalar(landscape_fetch->getHeight()));
}
LandscapeFetch Class
Members
LandscapeFetch ( ) #
The LandscapeFetch constructor.Vec3 getPosition ( ) #
Returns the coordinates of the fetch/intersection point.Return value
Fetch/intersection point coordinates as a three-component vector.float getHeight ( ) #
Returns the height value at the point.Return value
Height value at the point.vec3 getNormal ( ) #
Returns normal vector coordinates at the point.To get valid normal information via this method, engage normal data for the fetch/intersection request.
Return value
Normal vector coordinates at the point.vec4 getAlbedo ( ) #
Returns albedo color information at the point.To get valid albedo color information via this method, engage albedo data for the fetch/intersection request.
Return value
Albedo color at the point as a 4 component vector (R, G, B, A).int isIntersection ( ) #
Returns a value indicating if an intersection was detected.Return value
1 if an intersection was detected; otherwise, 0.float getMask ( int num ) #
Returns information stored for the point in the detail mask with the specified number.To get valid detail mask information via this method, engage mask data for the fetch/intersection request.
Arguments
- int num - Number of the detail mask in the [0; 19] range.
Return value
Value for the point stored in the detail mask with the specified number.void setUses ( int uses ) #
Sets multiple flags engaging/disengaging certain data types for the fetch/intersection request.Arguments
- int uses - Combination of data engagement flags to be set.
int getUses ( ) #
Returns the current state of flags engaging/disengaging certain data types for the fetch/intersection request.Return value
Current combination of data engagement flags.void setUsesHeight ( int height ) #
Sets a value indicating if heights data is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point). This option is enabled by default.Arguments
- int height - 1 to engage height data in the fetch/intersection request, 0 - to disengage.
int isUsesHeight ( ) #
Returns a value indicating if heights data is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point). This option is enabled by default.Return value
1 if heights data is engaged in the fetch/intersection request; otherwise, 0.void setUsesNormal ( int normal ) #
Sets a value indicating if normals data is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point).Enable this option to get normal information for the point.
Arguments
- int normal - 1 to engage normals data in the fetch/intersection request, 0 - to disengage.
int isUsesNormal ( ) #
Returns a value indicating if normals data is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point).Enable this option to get normal information for the point.
Return value
1 if normals data is engaged in the fetch/intersection request; otherwise, 0.void setUsesAlbedo ( int albedo ) #
Sets a value indicating if albedo data is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point).Enable this option to get albedo information for the point.
Arguments
- int albedo - 1 to engage albedo data in the fetch/intersection request, 0 - to disengage.
int isUsesAlbedo ( ) #
Returns a value indicating if albedo data is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point).Enable this option to get albedo information for the point.
Return value
1 if albedo data is engaged in the fetch/intersection request; otherwise, 0.void setUsesMask ( int num, int value ) #
Sets a value indicating if data of the specified detail mask is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point).Enable this option to get detail mask data for the point.
Arguments
- int num - Detail mask number in the [0; 19] range.
- int value - 1 to engage data of the specified detail mask in the fetch/intersection request, 0 - to disengage.
int isUsesMask ( int num ) #
Returns a value indicating if data of the specified detail mask is engaged in the fetch/intersection request. When the data type is engaged, you can obtain it via the corresponding get() method. Disengaging unnecessary data when performing requests saves some performance (e.g., you can engage albedo data only if you need only color information at a certain point).Enable this option to get detail mask data for the point.
Arguments
- int num - Detail mask number in the [0; 19] range.
Return value
1 if data of the specified detail mask is engaged in the fetch/intersection request; otherwise, 0.void setHolesEnabled ( int albedo ) #
Sets a value indicating if checking for terrain holes in the fetch/intersection request is enabled. This option is enabled by default. When disabled terrain holes created using decals are ignored.Arguments
- int albedo - 1 to enable checking for terrain holes in the fetch/intersection request, 0 - to disable it.
int isHolesEnabled ( ) #
Returns a value indicating if checking for terrain holes in the fetch/intersection request is enabled. This option is enabled by default. When disabled terrain holes created using decals are ignored.Return value
1 if checking for terrain holes in the fetch/intersection request is enabled; otherwise, 0.void setIntersectionPrecision ( float begin ) #
Sets a new precision value to be used for intersection detection requested by intersectionForce() and intersectionAsync() methods.Arguments
- float begin - Precision for intersection detection as a fraction of maximum precision in the [0; 1] range. The default value is 0.5f. Maximum precision is determined by the Engine on the basis of the data of your Landscape Terrain.
float getIntersectionPrecision ( ) #
Returns the current precision value used for intersection detection requested by intersectionForce() and intersectionAsync() methods.Return value
Precision for intersection detection as a fraction of maximum precision in the [0; 1] range. The default value is 0.5f. Maximum precision is determined by the Engine on the basis of the data of your Landscape Terrain.void setIntersectionPositionBegin ( Vec3 begin ) #
Sets the coordinates of the starting point for intersection detection.Arguments
- Vec3 begin - Three-component vector specifying starting point coordinates along X, Y, and Z axes.
Vec3 getIntersectionPositionBegin ( ) #
Returns the coordinates of the starting point for intersection detection.Return value
Three-component vector specifying starting point coordinates along X, Y, and Z axes.void setIntersectionPositionEnd ( Vec3 end ) #
Sets the coordinates of the end point for intersection detection.Arguments
- Vec3 end - Three-component vector specifying end point coordinates along X, Y, and Z axes.
Vec3 getIntersectionPositionEnd ( ) #
Returns the coordinates of the end point for intersection detection.Return value
Three-component vector specifying end point coordinates along X, Y, and Z axes.void setFetchPosition ( Vec2 position ) #
Sets a point for which terrain data is to be fetched.Arguments
- Vec2 position - Two-component vector specifying point coordinates along X and Y axes.
Vec2 getFetchPosition ( ) #
Returns the current point for which terrain data is to be fetched.Return value
Two-component vector specifying point coordinates along X and Y axes.int fetchForce ( ) #
Fetches terrain data in forced mode for the point specified by the setFetchPosition(). You can use the fetchAsync() method to reduce load, when an instant result is not required.Return value
1 if terrain data was successfully obtained for the specified point; otherwise, 0.int fetchForce ( Vec2 position ) #
Fetches terrain data in forced mode for the specified point. You can use the fetchAsync() method to reduce load, when an instant result is not required.Arguments
- Vec2 position - Coordinates of the point.
Return value
1 if terrain data was successfully obtained for the specified point; otherwise, 0.int intersectionForce ( ) #
Performs tracing along the line from the p0 point specified by the setIntersectionPositionBegin() to the p1 point specified by the setIntersectionPositionEnd() to find an intersection with the terrain in forced mode. You can use the intersectionAsync() method to reduce load, when an instant result is not required.Return value
1 if an intersection with the terrain was found; otherwise, 0.int intersectionForce ( Vec3 p0, Vec3 p1 ) #
Performs tracing along the line from the p0 point to the p1 point to find an intersection with the terrain in forced mode. You can use the intersectionAsync() method to reduce load, when an instant result is not required.Arguments
Return value
1 if an intersection with the terrain was found; otherwise, 0.void fetchAsync ( int critical = false ) #
Fetches terrain data for the point specified by the setFetchPosition() in asynchronous mode (the corresponding task shall be put to the queue, to wait until the result is obtained use the wait() method). For an instant result use the fetchForce() method.Arguments
- int critical - 1 to set high priority for the fetch task, 0 - to set normal priority.
void fetchAsync ( Vec2 position, int critical = false ) #
Fetches terrain data for the specified point in asynchronous mode (the corresponding task shall be put to the queue, to wait until the result is obtained use the wait() method). For an instant result use the fetchForce() method.Arguments
- Vec2 position - Coordinates of the point.
- int critical - 1 to set high priority for the fetch task, 0 - to set normal priority.
void intersectionAsync ( int critical = false ) #
Performs tracing along the line from the p0 point specified by the setIntersectionPositionBegin() to the p1 point specified by the setIntersectionPositionEnd() to find an intersection with the terrain in asynchronous mode (the corresponding task shall be put to the queue, to wait until the result is obtained use the wait() method). For an instant result use the intersectionForce() method.Arguments
- int critical - 1 to set high priority for the intersection task, 0 - to set normal priority.
void intersectionAsync ( Vec3 p0, Vec3 p1, int critical = false ) #
Performs tracing along the line from the p0 point to the p1 point to find an intersection with the terrain in asynchronous mode (the corresponding task shall be put to the queue, to wait until the result is obtained use the wait() method). For an instant result use the intersectionForce() method.Arguments
- Vec3 p0 - Coordinates of the p0 point.
- Vec3 p1 - Coordinates of the p1 point.
- int critical - 1 to set high priority for the intersection task, 0 - to set normal priority.
static void fetchForce ( ) #
Fetches (batch) terrain data in forced mode for the point specified by the setFetchPosition(). You can use the fetchAsync() method to reduce load, when an instant result is not required.Arguments
static void intersectionForce ( ) #
Performs tracing (batch) along the line from the p0 point specified by the setIntersectionPositionBegin() to the p1 point specified by the setIntersectionPositionEnd() to find an intersection with the terrain in forced mode. You can use the intersectionAsync() method to reduce load, when an instant result is not required.Arguments
static void fetchAsync ( int critical = false ) #
Fetches (batch) terrain data for the point specified by the setFetchPosition() in asynchronous mode (the corresponding task shall be put to the queue, to wait until the result is obtained use the wait() method). For an instant result use the fetchForce() method.Arguments
- int critical - 1 to set high priority for the fetch task, 0 - to set normal priority.
static void intersectionAsync ( int critical = false ) #
Performs tracing (batch) along the line from the p0 point specified by the setIntersectionPositionBegin() to the p1 point specified by the setIntersectionPositionEnd() to find an intersection with the terrain in asynchronous mode (the corresponding task shall be put to the queue, to wait until the result is obtained use the wait() method). For an instant result use the intersectionForce() method.Arguments
- int critical - 1 to set high priority for the intersection task, 0 - to set normal priority.
void wait ( ) #
Waits for completion of the fetch operation. As the operation is completed you can obtain necessary data via get*() methods.static void wait ( ) #
Waits for completion of the specified fetch operations. As the operations are completed you can obtain necessary data via get*() methods.Arguments
int isAsyncCompleted ( ) #
Returns a value indicating if async operation is completed. As the operation is completed you can obtain necessary data via get*() methods.Return value
1 if async operation is completed; otherwise, 0.Last update:
2021-12-13
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)