Unigine.World Class
This class provides functionality for the world script. It contains methods required for loading the world with all its nodes, managing a spatial tree and handling nodes collisions and intersections.
Loading of nodes on demand is managed via the AsyncQueue Class.
See also#
- AsyncQueue Class to manage loading nodes and other resources on demand.
- The Intersections article demonstrating how to use intersection-related functions
World Class
Properties
int NumUpdateNodes#
bool IsUnpackNodeReferences#
bool IsAutoReloadNodeReferences#
float UpdateGridSize#
float Distance#
float Budget#
string Data#
bool IsLoaded#
string ScriptName#
string Name#
string Path#
bool IsScriptExecute#
Members
bool GetCollision ( WorldBoundBox bb, Object[] objects ) #
Searches for all collider objects within a given bounding box.Arguments
- WorldBoundBox bb - Bounding box.
- Object[] objects - Array with collider objects' smart pointers.
Return value
1 if collider objects are found; otherwise, 0.bool GetCollision ( WorldBoundSphere bs, Object[] objects ) #
Searches for all collider objects within a given bounding sphere.Arguments
- WorldBoundSphere bs - Bounding sphere.
- Object[] objects - Array with collider objects' smart pointers.
Return value
1 if collider objects are found; otherwise, 0.bool GetCollision ( Vec3 p0, Vec3 p1, Object[] objects ) #
Performs tracing from the p0 point to the p1 point to find all collider objects intersecting the line. This function detects intersection with surfaces (polygons) of mesh and terrain objects.
Collisions with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Collision flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - The start point coordinates.
- Vec3 p1 - The end point coordinates.
- Object[] objects - Array with collider objects' smart pointers.
Return value
1 if collider objects are found; otherwise, 0.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, Vec3[] ret_point, vec3[] ret_normal, vec4[] ret_texcoord, int[] ret_index, int[] ret_instance, int[] ret_surface ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces of a mesh. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- Vec3[] ret_point - Intersection point of the line and object.
- vec3[] ret_normal - Normal vector to the intersection point.
- vec4[] ret_texcoord - Texture coordinates of the intersection point (vec4, where vec4.xy is for the first (0) UV channel, vec4.zw is for the second (1) UV channel).
- int[] ret_index - Intersected triangle (polygon) number.
- int[] ret_instance - Intersected instance number.
Intersected instance number can be obtained for the following classes:
- int[] ret_surface - Intersected surface number.
Return value
Intersected object.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, Node[] exclude, Vec3[] ret_point, vec3[] ret_normal, vec4[] ret_texcoord, int[] ret_index, int[] ret_instance, int[] ret_surface ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- Node[] exclude - The list of nodes to be excluded.
- Vec3[] ret_point - Intersection point of the line and object.
- vec3[] ret_normal - Normal vector to the intersection point.
- vec4[] ret_texcoord - Texture coordinates of the intersection point (vec4, where vec4.xy is for the first (0) UV channel, vec4.zw is for the second (1) UV channel).
- int[] ret_index - Intersected triangle (polygon) number.
- int[] ret_instance - Intersected instance number.
Intersected instance number can be obtained for the following classes:
- int[] ret_surface - Intersected surface number.
Return value
Intersected object.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, WorldIntersection intersection ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- WorldIntersection intersection - WorldIntersection object to be filled.
Return value
First intersected object.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, WorldIntersectionNormal intersection ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- WorldIntersectionNormal intersection - WorldIntersectionNormal object to be filled.
Return value
First intersected object.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, WorldIntersectionTexCoord intersection ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- WorldIntersectionTexCoord intersection - WorldIntersectionTexCoord object to be filled.
Return value
First intersected object.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, Node[] exclude, WorldIntersection intersection ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- Node[] exclude - The list of nodes to be excluded.
- WorldIntersection intersection - WorldIntersection object to be filled.
Return value
First intersected object.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, Node[] exclude, WorldIntersectionNormal intersection ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- Node[] exclude - The list of nodes to be excluded.
- WorldIntersectionNormal intersection - WorldIntersectionNormal object to be filled.
Return value
First intersected object.Object GetIntersection ( Vec3 p0, Vec3 p1, int mask, Node[] exclude, WorldIntersectionTexCoord intersection ) #
Performs tracing from the p0 point to the p1 point to find the first object intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- int mask - Intersection mask. If 0 is passed, the function will return NULL.
- Node[] exclude - The list of nodes to be excluded.
- WorldIntersectionTexCoord intersection - WorldIntersectionTexCoord object to be filled.
Return value
First intersected object.bool GetIntersection ( Vec3 p0, Vec3 p1, Object[] objects ) #
Performs tracing from the p0 point to the p1 point to find objects that intersecting the line. This function detects intersection with surfaces (polygons) of meshes. An intersection can be found only if an object is matching the intersection mask.
Intersections with the surface can be found only if the following conditions are fulfilled:
- The surface is enabled.
- Per-surface Intersection flag is enabled.
- The surface has a material assigned.
Arguments
- Vec3 p0 - Coordinates of the line start point.
- Vec3 p1 - Coordinates of the line end point.
- Object[] objects - Array of intersected objects.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundBox bb, Object[] objects ) #
Searches for intersections with objects that are found in a given bounding box.
Arguments
- WorldBoundBox bb - Bounding box where intersection search will be performed.
- Object[] objects - Array of intersected objects.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundSphere bs, Object[] objects ) #
Searches for intersections with objects that are found in a given bounding sphere.
Arguments
- WorldBoundSphere bs - Bounding sphere where intersection search will be performed.
- Object[] objects - Array of intersected objects.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundFrustum bf, Object[] objects ) #
Searches for intersections with objects that are found in a given bounding frustum.
Arguments
- WorldBoundFrustum bf - Bounding frustum where intersection search will be performed.
- Object[] objects - Array of intersected objects.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundBox bb, Node[] nodes ) #
Searches for intersections with nodes that are found in a given bounding box.
Arguments
- WorldBoundBox bb - Bounding box where intersection search will be performed.
- Node[] nodes - Array of intersected nodes.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundSphere bs, Node[] nodes ) #
Searches for intersections with nodes that are found in a given bounding sphere.
Arguments
- WorldBoundSphere bs - Bounding sphere where intersection search will be performed.
- Node[] nodes - Array of intersected nodes.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundBox bb, Node.TYPE type, Node[] nodes ) #
Searches for intersections with specified type of nodes that are found in a given bounding box.
Arguments
- WorldBoundBox bb - Bounding box where intersection search will be performed.
- Node.TYPE type - Node type filter. Only the nodes of the specified type will be checked.
- Node[] nodes - Array of intersected nodes.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundSphere bs, Node.TYPE type, Node[] nodes ) #
Searches for intersections with specified type of nodes that are found in a given bounding sphere.
Arguments
- WorldBoundSphere bs - Bounding sphere where intersection search will be performed.
- Node.TYPE type - Node type filter. Only the nodes of the specified type will be checked.
- Node[] nodes - Array of intersected nodes.
Return value
1 if intersections are found; otherwise, 0.bool GetIntersection ( WorldBoundFrustum bf, Node.TYPE type, Node[] nodes ) #
Searches for intersections with specified type of nodes that are found in a given bounding frustum.
Arguments
- WorldBoundFrustum bf - Bounding frustum where intersection search will be performed.
- Node.TYPE type - Node type filter. Only the nodes of the specified type will be checked.
- Node[] nodes - Array of intersected nodes.
Return value
1 if intersections are found; otherwise, 0.int LoadWorld ( string name ) #
Loads a world from a file and replaces the current world with it.Arguments
- string name - Name of the file describing the world.
Return value
1 if the world is loaded successfully; otherwise, 0.Node GetNode ( int id ) #
Returns a node by its ID. This can be any node: either created dynamically in run-time or loaded from the *.world file.Arguments
- int id - Node ID.
Return value
Node smart pointer if the node with the specified ID exists; otherwise, NULL.bool IsNode ( int id ) #
Checks if a node with a given ID exists in the world.Arguments
- int id - Node ID.
Return value
1 if the node with the given ID exists; otherwise, 0.void GetNodes ( Node[] nodes ) #
Gets all nodes (either loaded from the *.world file or created dynamically at run time).Arguments
- Node[] nodes - Return array with node smart pointers.
Node GetUpdateNode ( int num ) #
Returns an updated node by its ID.Arguments
- int num - Node ID.
Return value
The node smart pointer, if found; otherwise - 0.void AddUpdateNode ( Node node ) #
Adds a node that should be updated even if it is outside of the viewing frustum. This function should be called every frame.Arguments
- Node node - Node to be updated.
void AddUpdateNodes ( Node[] nodes ) #
Adds a node array that should be updated even if the nodes are outside of the viewing frustum. This function should be called every frame.Arguments
- Node[] nodes - Nodes array to be updated.
int AddWorld ( string name ) #
Loads a world from a file and adds it to the current world.Arguments
- string name - Name of the file describing the world.
Return value
1 if the world is loaded and added successfully; otherwise, 0.int ClearNode ( string name ) #
Clears a cache of a given node.Arguments
- string name - File with the node.
Return value
1 if the cache is cleared successfully; otherwise, 0.Node LoadNode ( string name, int cache = 1 ) #
Loads a node from a file. If the node is loaded successfully, it does not belong to any node hierarchy or list, so be careful and make sure to handle it properly, when it is no longer needed.Arguments
- string name - Path to the *.node file.
- int cache - 1 to use the file cache, 0 not to use.
Return value
Loaded node; NULL if the node cannot be loaded.int LoadNodes ( string name, Node[] nodes ) #
Loads nodes from a file.Arguments
- string name - Path to the *.node file.
- Node[] nodes - Array of nodes' smart pointers to which the loaded nodes are appended.
Return value
1 if the nodes are loaded successfully; otherwise, 0.int SaveNode ( string name, Node node, int binary = 0 ) #
Saves a given node to a file.Arguments
- string name - Path to the *.node file.
- Node node - Pointer to the node to save.
- int binary - If set to 1, the node is saved to the binary *.xml. This file cannot be read, but using it speeds up the saving of the node and requires less disk space.
Return value
1 if the node is saved successfully; otherwise, 0.int SaveNodes ( string name, Node[] nodes, int binary = 0 ) #
Saves nodes to a file.Arguments
- string name - Path to the *.node file.
- Node[] nodes - Array of nodes' smart pointers to be saved.
- int binary - If set to 1, the node is saved to the binary *.xml. This file cannot be read, but using it speeds up the saving of the node and requires less disk space.
Return value
1 if the nodes are saved successfully; otherwise, 0.void UpdateSpatial ( ) #
Updates the node BSP (binary space partitioning) tree.
The engine calls this method automatically each frame after the world script update() code is executed. As a new node becomes a part of the BSP tree only after this method is called, all engine subsystems (renderer, physics, sound, pathfinding, collisions, intersections, etc.) can process this node only in the next frame. If you need the subsystem to process the node in the very first frame, you can call the updateSpatial() method manually. The engine will call this method automatically after the update() code is executed anyways.
int RemoveNode ( Node node, int with_children = 1 ) #
Deletes a given node completely.Arguments
- Node node - Node to be removed
- int with_children - 1 — update the target parent nodes along with all their children nodes; 0 — update the target parent nodes without their children nodes.
Return value
1 if the node is removed successfully; otherwise, 0.void SetScriptExecute ( bool execute ) #
Sets a value indicating if a logic script associated with the world is to be loaded with it.Arguments
- bool execute - true - to load the world along with the associated logic script (if any), false - to ignore it.
bool IsScriptExecute ( ) #
Returns a value indicating if a logic script associated with the world is to be loaded with it.Return value
true if a logic script associated with the world is to be loaded with it; otherwise, false.bool ReleaseNode ( Node node ) #
Releases the specified node. After calling this method the node shall no longer be owned by the world, and won't be deleted automatically on closing the world.Arguments
- Node node - Node to be released by the world.
Return value
true if the specified node was successfully released by the world; otherwise, false.bool GrabNode ( Node node ) #
Arguments
- Node node - Node to be grabbed by the world.