NodeExtern 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 UnigineScipt (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.
Inherits: | Node |
NodeExtern is a custom user-defined node created via API. The NodeExtern class is a wrapper for implementation of a custom node class inherited from the NodeExternBase class.
A NodeExtern node is created when the engine loads an instance of the custom node class. It can also be created directly by using the class constructor with a custom node class ID as an argument. In both cases, the NodeExtern node wraps the custom node class inherited from the NodeExternBase.
A custom user-defined node is created as follows:
The custom user-defined node can be implemented on the C++ side only. So you should implement the custom node class in C++ and then use it on the C++ or UnigineScript side.
- Inherit a custom node class from NodeExternBase:
#include <UnigineNodes.h> using namespace Unigine; // inherit a custom class from NodeExternBase class MyNode : public NodeExternBase { };
- Implement logic of the custom node and register the class via NodeExternBase::addClassID(): The custom node class isn't a node, as the NodeExternBase class isn't inherited from the Node class.If required, the custom node class can be exported to UnigineScript.
#include <UnigineNodes.h> #include <UnigineEngine.h> #include "AppSystemLogic.h" #include "AppWorldLogic.h" #include "AppEditorLogic.h" using namespace Unigine; // inherit a custom class from NodeExternBase class MyNode : public NodeExternBase { public: // constructors MyNode(){} MyNode(void *node) : NodeExternBase(node){} // destructor virtual ~MyNode(){} // unique class ID virtual int getClassID() {return 1;} // set world transformation of the node void setWorldTransform(const UNIGINE_MAT4 &transform) {getNode()->setWorldTransform(transform);} // other methods // ... }; int main(int argc,char *argv[]) { // register the MyNode class NodeExternBase::addClassID<MyNode>(1); Unigine::EnginePtr engine(UNIGINE_VERSION,argc,argv); AppSystemLogic system_logic; AppWorldLogic world_logic; AppEditorLogic editor_logic; engine->main(&system_logic,&world_logic,&editor_logic); return 0; }
- Create a custom node in one of the following ways:
If the class has been exported to UnigineScript, you can perform the same on the UnigineScript side:
// create a MyNode pointer directly: a NodeExtern node will be created as well MyNode *my_node_0 = new MyNode(); // obtain the NodeExtern node my_node_0->getNodeExtern(); // create a NodeExtern instance by MyNode's class ID NodeExternPtr my_node_1 = NodeExtern::create(1); // obtain the MyNode pointer if required MyNode *my_node_2 = (MyNode*)my_node_1->getNodeExtern();
// create a MyNode pointer directly: a NodeExtern node will be created as well MyNode my_node_0 = new MyNode(); // obtain the NodeExtern node my_node_0.getNodeExtern(); // create a NodeExtern instance by MyNode's class ID NodeExtern my_node_1 = new NodeExtern(1); // obtain MyNode if required MyNode my_node_2 = class_cast("MyNode", node.getNodeExtern());
See Also#
- The NodeExternBase class for the complete usage example of the NodeExtern and NodeExternBase classes.
- A C++ API sample <UnigineSDK>/source/samples/Api/Nodes/NodeExtern
NodeExtern Class
Members
static NodeExtern ( int class_id ) #
Constructor. Creates a custom user-defined node. An instance of the custom node class will be created as well.Arguments
- int class_id - Unique class ID.
int getClassID ( ) #
Returns the class ID of the node.Return value
Class ID if the node exists; otherwise, 0.NodeExternBase getNodeExtern ( ) #
Returns the pointer to the custom node class.// create a NodeExtern instance by MyNode's class ID
NodeExtern my_node_1 = new NodeExtern(1);
// get MyNode
MyNode my_node_2 = class_cast("MyNode", node.getNodeExtern());
Return value
Pointer to the custom node class.static int type ( ) #
Returns the type of the node.Return value
NodeExtern type identifier.Last update:
2020-07-31
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)