Node Class
In terms of Unigine, all of the objects added into the scene are called nodes. Nodes can be of different types, determining their visual representation and behavior.
The node is created and stored in the world. All changes are saved into the .world file.
The node can be also saved into an external .node file and then imported into the world when necessary. Also it is possible to create a reference to the exported node.
You can associate any string data (written directly into a *.node or a *.world file) or an arbitrary user variable with a node.
See Also#
- How to handle ownership
- How to work with the node's matrix transformations
Creating a Node#
The Node class doesn't provide creating of a node. You can create an instance of any class inherited from the Node class and then operate it as it is an instance of the Node class.
For example:
- Use a mesh-file to create an instance of the ObjectMeshStatic class. This class is inherited from the Node class.
- Operate the ObjectMeshStatic instance as a node.
// unigine_project.cpp
#include <core/unigine.h>
int init() {
// create an instance of any class inherited from the Node class (e.g. ObjectMeshStatic)
ObjectMeshStatic object_mesh = new ObjectMeshStatic("core/meshes/box.mesh");
// operate the ObjectMeshStatic as a node
return 1;
}
Editing a Node and Saving Changes#
The Node class contains common settings of the node. Also each node has special settings, which vary depending on the type of the node.
Editing the node also includes editing materials and properties assigned to the node.
For the edited node to be saved in the .world file, you should enable the corresponding option via the setSaveToWorldEnabled() method.
For example:
- Create a box mesh by using the Mesh class.
- Save the mesh on the disk. It is required as the node we are going to export need to reference to a mesh stored on the disk.
- Use the saved .mesh file to create an instance of the ObjectMeshDynamic class. This class is inherited from the Node class.
- Edit the node and then save the world by calling the world_saveconsole command.
// unigine_project.cpp
#include <core/unigine.h>
int init() {
// create a mesh
Mesh mesh = new Mesh();
mesh.addBoxSurface("box_0", vec3(1.0f));
// save a mesh into a file on the disk
mesh.save("unigine_project/meshes/my_mesh.mesh");
// create an instance of any class inherited from the Node class (e.g. ObjectMeshDynamic)
ObjectMeshDynamic object_mesh = new ObjectMeshDynamic("unigine_project/meshes/my_mesh.mesh");
// change the node name
object_mesh.setName("my_node");
// change node transformation
object_mesh.setWorldTransform(translate(Vec3(0.0f, 0.0f, 2.0f)));
// save node changes in the .world file
engine.console.run("world_save");
return 1;
}
Exporting and Importing a Node#
To export a node stored in the world into the external .node file, you should pass it to the saveNode() method of the World class.
To import the existing node stored in the .node file to the world, you should call the loadNode() method of the World class.
For example:
- Create a box mesh by using the Mesh class.
- Save the mesh on the disk. It is required as the node we are going to export need to reference to a mesh stored on the disk.
- Use the saved .mesh file to create an instance of the ObjectMeshStatic class. This class is inherited from the Node class.
- Export the node to an external .node file.
- Import the previously exported node and add it to the editor to check the result.
// unigine_project.cpp
#include <core/unigine.h>
int init() {
// create a mesh
Mesh mesh = new Mesh();
mesh.addBoxSurface("box_0", vec3(1.0f));
// save a mesh into a file on the disk
mesh.save("unigine_project/meshes/my_mesh.mesh");
// create an instance of any class inherited from the Node class (e.g. ObjectMeshStatic)
ObjectMeshStatic object_mesh = new ObjectMeshStatic("unigine_project/meshes/my_mesh.mesh");
// export the node into a .node file
engine.world.saveNode("unigine_project/nodes/my_node.node",object_mesh);
// import the exported node to check the result
Node imported_node = engine.world.loadNode("unigine_project/nodes/my_node.node");
// set a position of the node
imported_node.setPosition(Vec3(4.0f, 0.0f, 1.0f));
return 1;
}
Deleting a Node#
By default each new node's lifetime matches the lifetime of the World (i.e. such node shall be deleted when the world is closed). But you can also choose node's lifetime to be managed:
- by the Engine - is this case the node shall be deleted automatically on Engine shutdown.
- manually - is this case the node should be deleted manually by the user.
To delete a node you can use the following two methods:
- deleteLater() - performs delayed deletion, in this case the object will be deleted during the next swap stage of the main loop (rendering of the object ceases immediately, but it still exists in memory for a while, so you can get it from its parent, for example). This method simplifies object deletion from a secondary thread, so you can call it and forget about the details, letting the Engine take control over the process of deletion, which can be used for future optimizations.
- deleteForce() - performs immediate deletion, which might be necessary in some cases. Calling this method for main-loop-dependent objects (e.g., nodes) is safe only when performed from the Main thread.
// unigine_project.cpp
#include <core/unigine.h>
int init() {
// create an instance of any class inherited from the Node class (e.g. ObjectMeshStatic)
ObjectMeshStatic object_mesh = new ObjectMeshStatic("core/meshes/box.mesh");
// do something with the node
// ...
// delete the node from the editor
engine.editor.removeNode(object_mesh);
return 1;
}
Node Class
Members
GeodeticPivot getGeodeticPivot() const#
Return value
Current geodetic pivot, or NULL if the node is not a child of a geodetic pivot node.void setVariable ( ) #
Arguments
- variable - The variable value.
getVariable() const#
Return value
Current variable value.void setWorldScale ( vec3 scale ) #
Arguments
- vec3 scale - The node scale in the world space.
vec3 getWorldScale() const#
Return value
Current node scale in the world space.void setWorldPosition ( Vec3 position ) #
Arguments
- Vec3 position - The node position in the world coordinates.
Vec3 getWorldPosition() const#
Return value
Current node position in the world coordinates.void setScale ( vec3 scale ) #
Arguments
- vec3 scale - The node scale in the local space.
vec3 getScale() const#
Return value
Current node scale in the local space.void setPosition ( Vec3 position ) #
Arguments
- Vec3 position - The node position in the local space.
Vec3 getPosition() const#
Return value
Current node position in the local space.vec3 getBodyAngularVelocity() const#
Return value
Current angular velocity of the node's physical body in the world space.vec3 getBodyLinearVelocity() const#
Return value
Current linear velocity of the node's physical body in the local space.BodyRigid getObjectBodyRigid() const#
Return value
Current rigid body assigned to the node if it is an object node; otherwise, NULL (0).Body getObjectBody() const#
Return value
Current physical body assigned to the node if it is an object node; otherwise, NULL (0).WorldBoundSphere getWorldBoundSphere() const#
Return value
Current bounding sphere of the node in world's coordinate system.WorldBoundBox getWorldBoundBox() const#
Return value
Current world bounding box.BoundSphere getBoundSphere() const#
Return value
Current bounding sphere of the node.BoundBox getBoundBox() const#
Return value
Current bounding box of the node.void setOldWorldTransform ( Mat4 transform ) #
Arguments
- Mat4 transform - The old (previous frame) transformation matrix for the node in the world coordinates.
Mat4 getOldWorldTransform() const#
Return value
Current old (previous frame) transformation matrix for the node in the world coordinates.void setWorldTransform ( Mat4 transform ) #
Arguments
- Mat4 transform - The transformation matrix of the node in the world coordinates.
Mat4 getWorldTransform() const#
Return value
Current transformation matrix of the node in the world coordinates.void setTransform ( Mat4 transform ) #
Arguments
- Mat4 transform - The transformation matrix of the node in local coordinates.
Mat4 getTransform() const#
Return value
Current transformation matrix of the node in local coordinates.int getNumProperties() const#
Return value
Current total number of properties associated with the node.Node getPossessor() const#
- NodeReference
- WorldCluster
- WorldClutter
- WorldLayer
Return value
Current node posessor, if it exists; otherwise, NULL.int getNumChildren() const#
Return value
Current number of child nodes.Node getRootNode() const#
Return value
Current root node for the node.void setParent ( Node parent ) #
Arguments
- Node parent - The parent of the node or NULL (0), if the node has no parent.
Node getParent() const#
Return value
Current parent of the node or NULL (0), if the node has no parent.int getNumAncestors() const#
Return value
Current number of ancestors of the node.void setName ( string name ) #
Arguments
- string name - The name of the node.
string getName() const#
Return value
Current name of the node.void setQuery ( ) #
Arguments
- query - The occlusion query is used for the node
isQuery() const#
Return value
Current occlusion query is used for the nodevoid setClutterInteractionEnabled ( bool enabled ) #
Arguments
- bool enabled - Set true to enable interaction with World Clutters and Mesh Clutters; false - to disable it.
bool isClutterInteractionEnabled() const#
Return value
true if interaction with World Clutters and Mesh Clutters is enabled; otherwise false.void setGrassInteractionEnabled ( bool enabled ) #
Arguments
- bool enabled - Set true to enable interaction with Grass nodes; false - to disable it.
bool isGrassInteractionEnabled() const#
Return value
true if interaction with Grass nodes is enabled; otherwise false.void setTriggerInteractionEnabled ( bool enabled ) #
Arguments
- bool enabled - Set true to enable interaction with World Triggers; false - to disable it.
bool isTriggerInteractionEnabled() const#
Return value
true if interaction with World Triggers is enabled; otherwise false.void setImmovable ( ) #
Arguments
- immovable - The the feature of the clutter (immovable) object for the node
isImmovable() const#
Return value
Current the feature of the clutter (immovable) object for the nodevoid setHandled ( bool handled ) #
Arguments
- bool handled - Set true to enable displaying of the node handle; false - to disable it.
bool isHandled() const#
Return value
true if displaying of the node handle is enabled; otherwise false.void setEnabled ( bool enabled ) #
Arguments
- bool enabled - Set true to enable the node; false - to disable it.
bool isEnabled() const#
Return value
true if the node is enabled; otherwise false.bool isExtern() const#
Return value
true if the node is an extern node; otherwise false.bool isField() const#
Return value
true if the node is a field node; otherwise false.bool isParticlesField() const#
Return value
true if the node is a particles field node; otherwise false.bool isSound() const#
Return value
true if the node is a sound node; otherwise false.bool isObstacle() const#
Return value
true if the node is an obstacle node; otherwise false.bool isNavigation() const#
Return value
true if the node is a navigation node; otherwise false.bool isPhysical() const#
Return value
true if the node is a physical node; otherwise false.bool isPlayer() const#
Return value
true if the node is a player node; otherwise false.bool isObject() const#
Return value
true if the node is an object node; otherwise false.bool isDecal() const#
Return value
true if the node is a decal node; otherwise false.bool isLight() const#
Return value
true if the node is a light source; otherwise false.bool isGeodetic() const#
Return value
true if the node is a geodetic-related node; otherwise false.bool isWorld() const#
Return value
true if the node is a world node; otherwise false.bool isImmovableSupported() const#
Return value
true if the node can be immovable; otherwise false.bool isSurfacesCollisionSupported() const#
Return value
true if collisions with node surfaces are supported; otherwise false.bool isSurfacesIntersectionSupported() const#
Return value
true if intersections with node surfaces are supported; otherwise false.string getTypeName() const#
Return value
Current name of the node type.getType() const#
Return value
Current node type identifier.void setID ( int id ) #
Arguments
- int id - The ID of the node.
int getID() const#
Return value
Current ID of the node.void setSaveToWorldEnabled ( bool enabled ) #
Arguments
- bool enabled - Set true to enable saving to *.world file for the node and all its children (if any); false - to disable it.
bool isSaveToWorldEnabled() const#
Return value
true if saving to *.world file for the node and all its children (if any) is enabled; otherwise false.bool isSaveToWorldEnabledSelf() const#
Return value
true if saving to *.world file for the node is enabled; otherwise false.void setShowInEditorEnabled ( bool enabled ) #
Arguments
- bool enabled - Set true to enable displaying in the World Hierarchy window of the UnigineEditor for the node; false - to disable it.
bool isShowInEditorEnabled() const#
Return value
true if displaying in the World Hierarchy window of the UnigineEditor for the node is enabled; otherwise false.bool isShowInEditorEnabledSelf() const#
Return value
true if displaying in the World Hierarchy window of the UnigineEditor for the node is enabled; otherwise false.int getNumWorldTriggers() const#
Return value
Current number of World Triggers inside which the node is located at the moment, or 0 if the node is not currently inside any World Trigger.WorldBoundSphere getSpatialBoundSphere() const#
Return value
Current bounding sphere with world coordinates.WorldBoundBox getSpatialBoundBox() const#
Return value
Current bounding box with world coordinates.bool isLandscapeLayer() const#
Return value
true if the node is a landscape layer is enabled; otherwise false.Mat4 getIWorldTransform() const#
Return value
Current inverse transformation matrix.Vec3 getOldWorldPosition() const#
Return value
Current old (previous frame) position of the node in the world coordinates.void setLifetime ( ) #
Arguments
- lifetime - The
getLifetime() const#
Return value
Currentstatic getEventNodeSwap() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventNodeClone() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventNodeChangeEnabled() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventNodeRemove() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventNodeLoad() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventCacheNodeAdd() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventPropertySurfaceRemove() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventPropertySurfaceAdd() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventPropertyNodeSwap() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventPropertyChangeEnabled() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventPropertyNodeRemove() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventPropertyNodeAdd() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static getEventPropertyNodeSlotsChanged() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.Node getAncestor ( int num ) #
Returns a node ancestor by its number.Arguments
- int num - Ancestor ID.
Return value
Ancestor node.Node getChild ( int num ) #
Returns a node child by its number.Arguments
- int num - Child ID.
Return value
Child node.int isChild ( Node n ) #
Checks if a given node is a child of the node.Arguments
- Node n - Node to check.
Return value
1 if the given node is a child; otherwise, 0.void setChildIndex ( Node n, int index ) #
Sets the index for a given child node of the node.Arguments
- Node n - Child node.
- int index - Node index.
int getChildIndex ( Node n ) #
Returns the index of a given child node of the node.Arguments
- Node n - Child node.
Return value
Node index.void setData ( string name, string data ) #
Updates user data associated with the node.- If the node was loaded from the *.node file, data is saved directly into the data tag of this file.
- If the node is loaded from the *.world file, data is saved into the Node data tag of the *.world file.
- If the node is loaded from the *.world file as a NodeReference, data will be saved to the NodeReference data tag of the *.world file.
Arguments
- string name - String containing a key identifying user data to be stored in the *.node file.
The "editor_data" key is reserved for the UnigineEditor.
- string data - New user data. Data can contain an XML formatted string.
string getData ( string name ) #
Returns user string data associated with the node.- If the node was loaded from the *.node file, data from the data tag of this file is returned.
- If the node is loaded from the *.world file, data from the Node data tag of the *.world file is returned.
- If the node is loaded from the *.world file as a NodeReference, data from the NodeReference data tag of the *.world file is returned.
Arguments
- string name - String containing a key identifying user data stored in the *.node file.
The "editor_data" key is reserved for the UnigineEditor.
Return value
User string data. Data can contain an XML formatted string.void updateEnabled ( ) #
Updates node's internal state according to the current "enabled" state.int isEnabledSelf ( ) #
Returns a value indicating if the node is enabled.Return value
1 if the node is enabled; otherwise, 0.void getHierarchy ( ) #
Retrieves the whole hierarchy of the node and puts it to the hierarchy buffer.Arguments
int setProperty ( int num ) #
Updates the node property with the specified number. A new internal property inherited from the one with the specified name will be set. Such internal properties are saved in a *.world or *.node file.Arguments
- int num - Node property number in the range from 0 to the total number of node properties.
Return value
1 if the specified node property is updated successfully; otherwise, 0.void setPropertyEnabled ( int num, int enable ) #
Enables or disables the node property with the specified number.Arguments
- int num - Node property number in the range from 0 to the total number of node properties.
- int enable - 1 to enable the specified node property, 0 to disable it.
int isPropertyEnabled ( int num ) #
Returns a value indicating if the node property with the specified number is enabled.Arguments
- int num - Node property number in the range from 0 to the total number of node properties.
Return value
1 if the specified property is enabled; otherwise, 0.void swapProperty ( int from_num, int to_num ) #
Swaps two properties with specified numbers in the list of properties associated with the node.Arguments
- int from_num - Number of the first node property to be swapped, in the range from 0 to the total number of node properties.
- int to_num - Number of the second node property to be swapped, in the range from 0 to the total number of node properties.
void clearProperties ( ) #
Clears the list of properties associated with the node.Property getProperty ( int num ) #
Returns a node property with the specified number if it exists.Arguments
- int num - Node property number in the range from 0 to the total number of node properties.
Return value
Node property.string getPropertyName ( int num ) #
Returns the name of a node property with the specified number.Arguments
- int num - Node property number in the range from 0 to the total number of node properties.
Return value
Property name, if exists; otherwise, NULL.int hasQueryForce ( ) #
Returns a value indicating if the Culled By Occlusion Queryoption is force-enabled for the node by the Engine.Return value
1 if the Culled By Occlusion Queryoption is force-enabled for the node by the Engine; otherwise, 0.void setRotation ( quat rot, int identity = 0 ) #
Sets the node rotation.Arguments
- quat rot - Quaternion representing node rotation in the local space.
- int identity - Flag indicating if node's scale is to be ignored or taken into account:
- 0 - node's scale is taken into account. In this case additional calculations are performed to extract current node's scale and apply it when building the final transformation matrix. These additional operations reduce performance and may lead to error accumulation.
- 1 - node's scale is ignored (assumed to be equal to 1 along all axes). Thus, the number of calculations performed for each rotation is reduced and error accumulation is minimal.
- It is recommended to set this flag for all non-scaled nodes to improve performance and accuracy.
- Scaling of nodes should be avoided whenever possible, as it requires addidional calculations and may lead to error accumulation.
quat getRotation ( ) #
Returns the node rotation.Return value
Quaternion representing node rotation in the local space.void setWorldRotation ( quat rot, int identity = 0 ) #
Sets the node rotation in the world space.Arguments
- quat rot - Node rotation in the world space.
- int identity - Flag indicating if node's scale is to be ignored or taken into account:
- 0 - node's scale is taken into account. In this case additional calculations are performed to extract current node's scale and apply it when building the final transformation matrix. These additional operations reduce performance and may lead to error accumulation.
- 1 - node's scale is ignored (assumed to be equal to 1 along all axes). Thus, the number of calculations performed for each rotation is reduced and error accumulation is minimal.
- It is recommended to set this flag for all non-scaled nodes to improve performance and accuracy.
- Scaling of nodes should be avoided whenever possible, as it requires addidional calculations and may lead to error accumulation.
quat getWorldRotation ( ) #
Returns the node rotation in the world space.Return value
Node rotation in the world space.void setTransformWithoutChildren ( Mat4 transform ) #
Sets the transformation matrix for the node in local coordinates (transformations of all node's children are not affected). This method can be used to change node's transformation relative to its children.Arguments
- Mat4 transform - New transformation matrix to be set for the node (local coordinates).
int getTypeID ( string type ) #
Returns the ID of a node type with a given name.Arguments
- string type - Node type name.
Return value
Node type ID, if such type exists; otherwise, -1.string getTypeName ( int type ) #
Returns the name of a node type with a given ID.Arguments
- int type - Node type ID.
Return value
Node type name.void setVariable ( string name, Variable v ) #
Sets the value of a variable with a given name. If such variable does not exist it will be added with a specified value.NodeDummy container = new NodeDummy();
if(container.hasVariable("key1") == 0) {
container.setVariable("key1",42);
}
int value = container.getVariable("key1");
container.removeVariable("key1");
Arguments
- string name - Variable name.
- Variable v - Variable value.
void setVariable ( string name, variable variable ) #
Sets the value of the single unnamed variable parameter of the node. If this variable does not exist it will be created with a specified value.Arguments
- string name - Variable name.
- variable variable - Variable value.
Variable getVariable ( string name ) #
Returns the variable with a given name.NodeDummy container = new NodeDummy();
if(container.hasVariable("key1") == 0) {
container.setVariable("key1",42);
}
int value = container.getVariable("key1");
container.removeVariable("key1");
Arguments
- string name - Variable name.
Return value
Variable if it exists; otherwise, variable with 0 value.variable getVariable ( string name ) #
Returns the variable with a given name.Arguments
- string name - Variable name.
Return value
Variable if it exists; otherwise, variable with 0 value.void setWorldParent ( Node n ) #
Sets the new parent of the node. Transformations of the current node will be done in the world coordinates.Arguments
- Node n - New parent node or NULL (0).
void setWorldTransformWithoutChildren ( Mat4 transform ) #
Sets the transformation matrix for the node in world coordinates (transformations of all node's children are not affected). This method can be used to change node's transformation relative to its children.Arguments
- Mat4 transform - New transformation matrix to be set for the node (world coordinates).
vec3 getBodyWorldVelocity ( Vec3 point ) #
Returns linear velocity of a point of the node's physical body in the world space.Arguments
- Vec3 point - Target point.
Return value
Linear velocity in the world space.void addChild ( Node n ) #
Adds a child to the node. Transformations of the new child will be done in the coordinates of the parent.Arguments
- Node n - New child node.
void addWorldChild ( Node n ) #
Adds a child to the node. Transformations of the new child will be done in the world coordinates.Arguments
- Node n - New child node.
clone ( ) #
Clones the node.Return value
Copy of the node or NULL (0), if an error occurred.int findChild ( string name ) #
Searches for a child node with a given name among the children of the node.Arguments
- string name - Name of the child node.
Return value
Child node number, if it is found; otherwise, -1.Node findNode ( string name, int recursive = 0 ) #
Searches for a node with a given name among the children of the node.Arguments
- string name - Name of the child node.
- int recursive - 1 if the search is recursive (i.e. performed for children of child nodes); otherwise, 0.
Return value
Child node, if it is found; otherwise, NULL.int hasVariable ( string name ) #
Returns a value indicating if the node has a variable parameter with a given name.NodeDummy container = new NodeDummy();
if(container.hasVariable("key1") == 0) {
container.setVariable("key1",42);
}
int value = container.getVariable("key1");
container.removeVariable("key1");
Arguments
- string name - Variable name.
Return value
1 if the node has a variable parameter with a given name; otherwise, 0.int hasVariable ( ) #
Returns a value indicating if the node has a single unnamed variable parameter.Return value
1 if the node has a single unnamed variable parameter; otherwise, 0.int loadWorld ( Xml xml ) #
Loads a node state from the Xml.Arguments
- Xml xml - Xml smart pointer.
Return value
1 if the node state is loaded successfully; otherwise, 0.void removeChild ( Node n ) #
Removes a child node (added by the addChild() method) from the list of children.Arguments
- Node n - Child node to remove.
int removeVariable ( string name ) #
Removes a variable parameter with a given name.NodeDummy container = new NodeDummy();
if(container.hasVariable("key1") == 0) {
container.setVariable("key1",42);
}
int value = container.getVariable("key1");
container.removeVariable("key1");
Arguments
- string name - Variable parameter name.
Return value
1 if the variable parameter is removed successfully; otherwise, 0.void removeWorldChild ( Node n ) #
Removes a child node (added by the addWorldChild() method) from the list of children.Arguments
- Node n - Child node to remove.
void renderVisualizer ( ) #
Renders a bounding box / sphere of the object.int saveState ( Stream stream ) #
Saves the state of a given node into a binary stream.- If a node is a parent for other nodes, states of these child nodes need to be saved manually.
- To save the state from a buffer, file or a message from a socket, make sure the stream is opened. For buffers and files, you also need to set the proper position for reading.
Example using saveState() and restoreState() methods:
// initialize a node and set its state
NodeDummy node = new NodeDummy();
node.setPosition(vec3(1, 1, 0));
// save state
Blob blob_state = new Blob();
node.saveState(blob_state);
// change state
node.setPosition(vec3(0, 0, 0));
// restore state
blob_state.seekSet(0); // returning the carriage to the start of the blob
node.restoreState(blob_state);
Arguments
- Stream stream - Stream to save node state data.
Return value
1 if node state is successfully saved; otherwise, 0.int restoreState ( Stream stream ) #
Restores the state of a given node from a binary stream.- If a node is a parent for other nodes, states of these child nodes need to be restored manually.
- To save the state into a buffer, file or a message from a socket, make sure the stream is opened. If necessary, you can set a position for writing for buffers and files.
Example using saveState() and restoreState() methods:
// initialize a node and set its state
NodeDummy node = new NodeDummy();
node.setPosition(vec3(1, 1, 0));
// save state
Blob blob_state = new Blob();
node.saveState(blob_state);
// change state
node.setPosition(vec3(0, 0, 0));
// restore state
blob_state.seekSet(0); // returning the carriage to the start of the blob
node.restoreState(blob_state);
Arguments
- Stream stream - Stream with saved node state data.
Return value
1 if node state is successfully restored; otherwise, 0.int saveWorld ( Xml xml ) #
Saves the node into the Xml.Arguments
- Xml xml - Xml smart pointer.
Return value
1 if the node is successfully saved; otherwise, 0.void swap ( Node n ) #
Swaps the nodes saving the pointers.Arguments
- Node n - Node to swap.
vec3 toLocal ( Vec3 p ) #
Converts a given vector in the world space to the node's local space.Arguments
- Vec3 p - Vector in the world space.
Return value
Vector in the local space.Vec3 toWorld ( vec3 p ) #
Converts a given vector in the local space to the world space.Arguments
- vec3 p - Vector in the local space.
Return value
Vector in the world space.void translate ( Vec3 t ) #
Translates the node relative to its local coordinate system: the parent node transformation isn't taken into account.Arguments
- Vec3 t - Translation vector.
void translate ( scalar x, scalar y, scalar z ) #
Translates the node relative to its local coordinate system: the parent node transformation isn't taken into account.Arguments
- scalar x - Node translation along the X axis, in units.
- scalar y - Node translation along the Y axis, in units.
- scalar z - Node translation along the Z axis, in units.
void worldTranslate ( Vec3 t ) #
Translates the node in the world space using the specified vector.Arguments
- Vec3 t - Translation vector.
void worldTranslate ( scalar x, scalar y, scalar z ) #
Translates the node in the world space using the values specified for the corresponding axes.Arguments
- scalar x - Node translation along the X axis, in units.
- scalar y - Node translation along the Y axis, in units.
- scalar z - Node translation along the Z axis, in units.
void worldLookAt ( ) #
Reorients the node to "look" at the target point and sets the given up vector:- If the node is a Player-related one, it will "look" at the target point along the negative Z axis. The Y axis will be oriented along the specified up vector.
- Other nodes will "look" at the target point along the Y axis. The Z axis will be oriented along the specified up vector.
Arguments
void worldLookAt ( ) #
Reorients the node to "look" at the target point. The up vector is oriented along the Z axis.- If the node is a Player-related one, it will "look" at the target point along the negative Z axis. The Y axis will be oriented along the world Z axis.
- Other nodes will "look" at the target point along the Y axis.
Arguments
void rotate ( quat r ) #
Rotates the node relative to its local coordinate system: the parent node transformation isn't taken into account. Rotation is determined by the specified quaternion.Arguments
- quat r - Rotation quaternion.
void rotate ( float angle_x, float angle_y, float angle_z ) #
Rotates the node in the world space according to specified Euler angles.Arguments
- float angle_x - Pitch angle, in degrees.
- float angle_y - Roll angle, in degrees.
- float angle_z - Yaw angle, in degrees.
void worldRotate ( quat r ) #
Rotates the node in the world space. Rotation is determined by the specified quaternion.Arguments
- quat r - Rotation quaternion.
void worldRotate ( float angle_x, float angle_y, float angle_z ) #
Rotates the node in the world space according to specified Euler angles.Arguments
- float angle_x - Pitch angle, in degrees.
- float angle_y - Roll angle, in degrees.
- float angle_z - Yaw angle, in degrees.
void setDirection ( ) #
Updates the direction vector of the node and reorients this node: the specified axis of the node becomes oriented along the specified vector in local coordinates. For example, after running the code below, you will get the X axis of the node pointed along the Y axis in local coordinates.// get the node
Node node = engine.world.getNodeByName("material_ball");
// set the X axis to be pointed along the Y axis in local coordinates
node.setDirection(vec3(0.0f,1.0f,0.0f),vec3(0.0f,0.0f,1.0f),AXIS_X);
Arguments
getDirection ( ) #
Returns the normalized direction vector pointing along the given node axis in local coordinates (i.e. relative to the node's parent). By default, the direction vector pointing along the negative Z axis of the node (in local coordinates) is returned. The direction vector always has a unit length.node.getDirection(node.isPlayer() ? AXIS_NZ : AXIS_Y); // forward direction vector
node.getDirection(node.isPlayer() ? AXIS_Z : AXIS_NY); // backward direction vector
node.getDirection(node.isPlayer() ? AXIS_Y : AXIS_Z); // upward direction vector
node.getDirection(node.isPlayer() ? AXIS_NY : AXIS_NZ); // down direction vector
node.getDirection(AXIS_X); // right direction vector
node.getDirection(AXIS_NX); // left direction vector
Arguments
Return value
Direction vector in local coordinates.void setWorldDirection ( ) #
Updates the direction vector of the node and reorients this node: the specified axis of the node becomes oriented along the specified vector in world coordinates. For example, after running the code below, you will get the X axis of the node pointed along the Y axis in world coordinates:// get the node
Node node = engine.world.getNodeByName("material_ball");
// set the X axis to be pointed along the Y axis in world coordinates
node.setWorldDirection(vec3(0.0f,1.0f,0.0f),vec3(0.0f,0.0f,1.0f),AXIS_X);
Arguments
getWorldDirection ( ) #
Returns the normalized direction vector pointing along the given node axis in world coordinates. By default, the direction vector pointing along the negative Z axis of the node is returned. The direction vector always has a unit length.node.getWorldDirection(node.isPlayer() ? AXIS_NZ : AXIS_Y); // forward direction vector
node.getWorldDirection(node.isPlayer() ? AXIS_Z : AXIS_NY); // backward direction vector
node.getWorldDirection(node.isPlayer() ? AXIS_Y : AXIS_Z); // upward direction vector
node.getWorldDirection(node.isPlayer() ? AXIS_NY : AXIS_NZ); // down direction vector
node.getWorldDirection(AXIS_X); // right direction vector
node.getWorldDirection(AXIS_NX); // left direction vector
Arguments
Return value
Direction vector in world coordinates.Node getCloneNode ( Node original_node ) #
Returns a node cloned from the specified original node.Arguments
- Node original_node - Original node that was cloned.
Return value
Clone of the specified original node if it exists; otherwise the original node itself.Property getCloneProperty ( Property original_property ) #
Returns a node property cloned from the specified original property.Arguments
- Property original_property - Original node property that was cloned.
Return value
Clone of the specified original node property if it exists; otherwise the original node property itself.void setSaveToWorldEnabledRecursive ( int enable ) #
Sets a value indicating if saving to *.world file is enabled for the node and all its children (if any).Arguments
- int enable - 1 to enable saving to *.world file for the node and all its children (if any); 0 to disable.
void setShowInEditorEnabledRecursive ( int enable ) #
Sets a value indicating if displaying in the World Hierarchy window of the UnigineEditor is enabled for the node and all its children (if any).Arguments
- int enable - 1 to enable displaying in the World Hierarchy window of the UnigineEditor for the node and all its children (if any); 0 to disable.
int getLifetimeSelf ( ) #
Returns the lifetime management type set for the node itself.Return value
One of the NODE_LIFETIME_* values.WorldBoundBox getHierarchyBoundBox ( int only_enabled_nodes = false ) #
Returns a bounding box with local coordinates that takes children into account, but doesn't participate in physics calculations. Exclusion of objects from the spatial tree significantly reduces the size of the tree and improves performance due to saving time on bounding box recalculation when transforming nodes.Arguments
- int only_enabled_nodes - Set 1 to obtain the result taking into account only the nodes in the hierarchy that are enabled, or 0 - to take into account all nodes in the hierarchy regardless of their enabled state.
Return value
The bounding box with world coordinates.WorldBoundSphere getHierarchyBoundSphere ( int only_enabled_nodes = false ) #
Returns a bounding sphere with local coordinates that takes children into account, but doesn't participate in physics calculations. Exclusion of objects from the spatial tree significantly reduces the size of the tree and improves performance due to saving time on bounding sphere recalculation when transforming nodes.Arguments
- int only_enabled_nodes - Set 1 to obtain the result taking into account only the nodes in the hierarchy that are enabled, or 0 - to take into account all nodes in the hierarchy regardless of their enabled state.
Return value
The bounding sphere with world coordinates.WorldBoundBox getHierarchyWorldBoundBox ( int only_enabled_nodes = false ) #
Returns a bounding box with world coordinates that takes children into account, but doesn't participate in physics calculations. Exclusion of objects from the spatial tree significantly reduces the size of the tree and improves performance due to saving time on bounding box recalculation when transforming nodes.Arguments
- int only_enabled_nodes - Set 1 to obtain the result taking into account only the nodes in the hierarchy that are enabled, or 0 - to take into account all nodes in the hierarchy regardless of their enabled state.
Return value
The bounding box with world coordinates.WorldBoundSphere getHierarchyWorldBoundSphere ( int only_enabled_nodes = false ) #
Returns a bounding sphere with world coordinates that takes children into account, but doesn't participate in physics calculations. Exclusion of objects from the spatial tree significantly reduces the size of the tree and improves performance due to saving time on bounding sphere recalculation when transforming nodes.Arguments
- int only_enabled_nodes - Set 1 to obtain the result taking into account only the nodes in the hierarchy that are enabled, or 0 - to take into account all nodes in the hierarchy regardless of their enabled state.
Return value
The bounding sphere with world coordinates.WorldBoundBox getHierarchySpatialBoundBox ( int only_enabled_nodes = false ) #
Returns a bounding box with world coordinates that takes all children and physics into account. This bounding box is used by the spatial tree.Arguments
- int only_enabled_nodes - Set 1 to obtain the result taking into account only the nodes in the hierarchy that are enabled, or 0 - to take into account all nodes in the hierarchy regardless of their enabled state.
Return value
The bounding box with world coordinates.WorldBoundSphere getHierarchySpatialBoundSphere ( int only_enabled_nodes = false ) #
Returns a bounding sphere with world coordinates that takes all children and physics into account. This bounding sphere is used by the spatial tree.Arguments
- int only_enabled_nodes - Set 1 to obtain the result taking into account only the nodes in the hierarchy that are enabled, or 0 - to take into account all nodes in the hierarchy regardless of their enabled state.
Return value
The bounding sphere with world coordinates.virtual void updateSpatialTree ( ) #
Updates node bounds in the spatial tree in the current frame. This method can be used in case you use some custom logic affecting node bounds or position and need to have your changes to be taken into account in the current frame, as well as to process such changes for your custom nodes ( ObjectExtern, NodeExtern) which are otherwise ignored. Calling this method enables you to apply changes for this node fast without complete tree recalculation. But you should be aware that node bounds fast-updated this way might be inaccurate (they can only be expanded, as shrinking will require tree recalculation). In case you need to have 100% accurate bounds in the current frame, call the World::updateSpatial()() method. You can also simply tell the spatial tree to update node bounds in the next frame via the updateSpatialTreeDelayed()() method.void updateSpatialTreeDelayed ( ) #
Mark node bounds in the spatial tree to be updated in the next frame (all bounds will be 100% accurate in this case unlike for the updateSpatialTree()() method). This method can be used in case you use some custom logic affecting node bounds or position, as well as to process such changes for your custom nodes ( ObjectExtern, NodeExtern) which are otherwise ignored. The changes will only be applied in the next frame, in case you need to have your changes to be taken into account right in the current frame use the World::updateSpatial()() method for 100% accurate bounds (slow), or the fast updateSpatialTree()() method which only expands node bounds if necessary.WorldTrigger getWorldTrigger ( int num ) #
Returns one of the World Triggers inside which the node is located at the moment by its number. For any node in the world, you can check whether it is currently inside any World Trigger and access any of such triggers by simply calling this method.Arguments
- int num - Number of the World Trigger in the list of World Triggers inside which the node is located at the moment.
Return value
World Trigger with the specified number inside which the node is located at the moment.UGUID getLostNodePropertyGUID ( int num ) #
Returns the GUID of a lost property assigned to the node. If for some reason a property assigned to the specified slot of the node is missing, this method can be used to get it's GUID.Arguments
- int num - Target property slot number.
Return value
Lost property GUID.void renderBounds ( int render_node_bound = true, int render_instance_bound = false ) #
Arguments
- int render_node_bound
- int render_instance_bound