This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
创建内容
内容优化
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Unigine::LandscapeFetch Class

Header: #include <UnigineObjects.h>

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:

  1. Create a new LandscapeFetch object instance.
  2. Set necessary parameters (e.g. which data layers are to be used, whether to enable holes or not, etc.).
  3. To get terrain data for a certain point call the fetchForce() method providing coordinates for the desired point.
    Notice
    You can also fetch terrain data asynchronously via the fetchAsync() method.
  4. 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#

Source code (C++)
// 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#

Source code (C++)
// 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.

Math::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.

Math::vec3 getNormal ( ) #

Returns normal vector coordinates at the point.
Notice
To get valid normal information via this method, engage normal data for the fetch/intersection request.

Return value

Normal vector coordinates at the point.

Math::vec4 getAlbedo ( ) #

Returns albedo color information at the point.
Notice
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).

bool isIntersection ( ) #

Returns a value indicating if an intersection was detected.

Return value

true if an intersection was detected; otherwise, false.

float getMask ( int num ) #

Returns information stored for the point in the detail mask with the specified number.
Notice
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 ( bool 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

  • bool height - true to engage height data in the fetch/intersection request, false - to disengage.

bool 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

true if heights data is engaged in the fetch/intersection request; otherwise, false.

void setUsesNormal ( bool 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).
Notice
Enable this option to get normal information for the point.

Arguments

  • bool normal - true to engage normals data in the fetch/intersection request, false - to disengage.

bool 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).
Notice
Enable this option to get normal information for the point.

Return value

true if normals data is engaged in the fetch/intersection request; otherwise, false.

void setUsesAlbedo ( bool 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).
Notice
Enable this option to get albedo information for the point.

Arguments

  • bool albedo - true to engage albedo data in the fetch/intersection request, false - to disengage.

bool 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).
Notice
Enable this option to get albedo information for the point.

Return value

true if albedo data is engaged in the fetch/intersection request; otherwise, false.

void setUsesMask ( int num, bool 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).
Notice
Enable this option to get detail mask data for the point.

Arguments

  • int num - Detail mask number in the [0; 19] range.
  • bool value - true to engage data of the specified detail mask in the fetch/intersection request, false - to disengage.

bool 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).
Notice
Enable this option to get detail mask data for the point.

Arguments

  • int num - Detail mask number in the [0; 19] range.

Return value

true if data of the specified detail mask is engaged in the fetch/intersection request; otherwise, false.

void setHolesEnabled ( bool 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

  • bool albedo - true to enable checking for terrain holes in the fetch/intersection request, false - to disable it.

bool 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

true if checking for terrain holes in the fetch/intersection request is enabled; otherwise, false.

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 ( const Math::Vec3 & begin ) #

Sets the coordinates of the starting point for intersection detection.

Arguments

  • const Math::Vec3 & begin - Three-component vector specifying starting point coordinates along X, Y, and Z axes.

Math::Vec3 getIntersectionPositionBegin ( ) const#

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 ( const Math::Vec3 & end ) #

Sets the coordinates of the end point for intersection detection.

Arguments

  • const Math::Vec3 & end - Three-component vector specifying end point coordinates along X, Y, and Z axes.

Math::Vec3 getIntersectionPositionEnd ( ) const#

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 ( const Math::Vec2 & position ) #

Sets a point for which terrain data is to be fetched.

Arguments

  • const Math::Vec2 & position - Two-component vector specifying point coordinates along X and Y axes.

Math::Vec2 getFetchPosition ( ) const#

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.

bool 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

true if terrain data was successfully obtained for the specified point; otherwise, false.

bool fetchForce ( const Math::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

  • const Math::Vec2& position - Coordinates of the point.

Return value

true if terrain data was successfully obtained for the specified point; otherwise, false.

bool 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

true if an intersection with the terrain was found; otherwise, false.

bool intersectionForce ( const Math::Vec3& p0, const Math::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

  • const Math::Vec3& p0 - Coordinates of the p0 point.
  • const Math::Vec3& p1 - Coordinates of the p1 point.

Return value

true if an intersection with the terrain was found; otherwise, false.

void fetchAsync ( bool 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

  • bool critical - true to set high priority for the fetch task, false - to set normal priority.

void fetchAsync ( const Math::Vec2& position, bool 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

  • const Math::Vec2& position - Coordinates of the point.
  • bool critical - true to set high priority for the fetch task, false - to set normal priority.

void intersectionAsync ( bool 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

  • bool critical - true to set high priority for the intersection task, false - to set normal priority.

void intersectionAsync ( const Math::Vec3& p0, const Math::Vec3& p1, bool 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

  • const Math::Vec3& p0 - Coordinates of the p0 point.
  • const Math::Vec3& p1 - Coordinates of the p1 point.
  • bool critical - true to set high priority for the intersection task, false - to set normal priority.

static void fetchForce ( const Vector< Ptr<LandscapeFetch> > & fetches ) #

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

  • const Vector< Ptr<LandscapeFetch> > & fetches - List of fetch requests to be completed.

static void intersectionForce ( const Vector< Ptr<LandscapeFetch> > & fetches ) #

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

  • const Vector< Ptr<LandscapeFetch> > & fetches - List of fetch requests to be completed.

static void fetchAsync ( const Vector< Ptr<LandscapeFetch> > & fetches, bool 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

  • const Vector< Ptr<LandscapeFetch> > & fetches - List of fetch requests to be completed.
  • bool critical - true to set high priority for the fetch task, false - to set normal priority.

static void intersectionAsync ( const Vector< Ptr<LandscapeFetch> > & fetches, bool 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

  • const Vector< Ptr<LandscapeFetch> > & fetches - List of fetch requests to be completed.
  • bool critical - true to set high priority for the intersection task, false - 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 ( const Vector< Ptr<LandscapeFetch> > & fetches ) #

Waits for completion of the specified fetch operations. As the operations are completed you can obtain necessary data via get*() methods.

Arguments

  • const Vector< Ptr<LandscapeFetch> > & fetches - List of fetch requests to be completed.

bool 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

true if async operation is completed; otherwise, false.

void * addStartCallback ( Unigine::CallbackBase * func ) #

Adds a callback function to be called on beginning of the fetch process. The signature of the callback function must be as follows:
Source code (C++)
void fetch_start_callback();

You can set a callback function as follows:

Source code (C++)
addStartCallback(MakeCallback(fetch_start_callback));

Example: Setting a fetch start callback function for a certain class:

Source code (C++)
// callback function implementing certain actions to be performed on beginning of the fetch process
void fetchStart()
{
	// insert your specific handling code here
}

// ...
virtual int AppWorldLogic::init()
{
	// setting the fetchStart() function to handle beginning of the fetch process
	LandscapeFetchPtr lf = LandscapeFetch::create();
	lf->addStartCallback(MakeCallback(&fetchStart));

	return 1;
}

Arguments

Return value

ID of the last added fetch start callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool removeStartCallback ( void * id ) #

Removes the specified callback from the list of file fetch start callbacks.

Arguments

  • void * id - Start callback ID obtained when adding it.

Return value

True if the fetch start callback with the given ID was removed successfully; otherwise false.

void clearStartCallback ( ) #

Clears all added fetch start callbacks.

void * addEndCallback ( Unigine::CallbackBase * func ) #

Adds a callback function to be called on fetch completion. The signature of the callback function must be as follows:
Source code (C++)
void fetch_end_callback();

You can set a callback function as follows:

Source code (C++)
addEndCallback(MakeCallback(fetch_end_callback));

Example: Setting a fetch completion callback function for a certain class:

Source code (C++)
// callback function implementing certain actions to be performed on fetch completion
void fetchEnd()
{
	// insert your specific handling code here
}

// ...
virtual int AppWorldLogic::init()
{
	// setting the fetchEnd() function to handle fetch completion
	LandscapeFetchPtr lf = LandscapeFetch::create();
	lf->addEndCallback(MakeCallback(&fetchEnd));
	
	return 1;
}

Arguments

Return value

ID of the last added fetch end callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool removeEndCallback ( void * id ) #

Removes the specified callback from the list of file fetch end callbacks.

Arguments

  • void * id - End callback ID obtained when adding it.

Return value

True if the fetch end callback with the given ID was removed successfully; otherwise false.

void clearEndCallback ( ) #

Clears all added fetch end callbacks.
Last update: 2022-03-10
Build: ()