WorldExpression Class
This class executes an arbitrary expression. For other nodes to move along with expression transformations, they should be assigned as WorldExpression children.
Attaching Script
There are two ways to write WorldExpression script:
- Directly in the editor (Nodes panel -> Expression -> Source field):
{ log.message("WorldExpression is updated\n"); }
- Attach a script file:
- Specify it in the File field (relative to the data directory, for example, project/scripts/world_script.h).
- Specify #include in the Source field:
{ #include <project/scripts/world_script.h> }
Creating Script
WorldExpression script can be implemented in the following way:
void __constructor__() { } // Create resources. This function is called on world load, when
// not all of the nodes can be loaded!
void __destructor__() { } // Delete created resources.
/*
*/
void my_update() { ... } // Code that the WorldExpression will execute for its child node each frame
// (when WorldExpression is in the view frustum or player is inside its radius).
my_update(); // Execute the update function.
Inter-Script Communication
Each WorldExpression has its own scope. You cannot directly set or get variables to or from the WorldExpression (as memory corruption occurs).
- If WorldExpression calls a function from a world script:
// World script namespace WorldScriptScope { void worldScriptFunc(string arg) { log.message("World script code: %s\n",arg); } }
// WorldExpression engine.world.call("WorldScriptScope::worldScriptFunc","hello from WorldExpression");
- If a world script calls a function from WorldExpression:
// World script namespace WorldScriptScope { void worldScriptFunc(WorldExpression expression) { expression.call("worldExpressionFunc","hello from the world script"); } }
// WorldExpression void worldExpressionFunc(string arg) { log.message("WorldExpression code: %s\n",arg); }
Script Functions
The following internal functions are available within the WorldExpression script:
- Node getNode() - returns the WorldExpression node.
- Node getChild(int num) - returns the WorldExpression child node by its number. If the child is not found, returns NULL.
- int getNumChilds() - returns the number of WorldExpression children.
- Node getParent() - returns the WorldExpression parent node. If there is no parent, returns NULL.
To get the WorldExpression node and its parent, you can write the following in the WorldExpression script:
Node node = getNode();
Node parent = node.getParent();
forloop(int i = 0; getNumChilds()) {
Node child = getChild(i);
log.message("The type of the node is: %s\n",child.getTypeName());
}
// this example shows the type of each WorldExpression child
WorldExpression Class
This class inherits from NodeMembers
WorldExpression (vec3 size = 1)
Constructor. Creates an arbitrary expression to be executed.Arguments
- vec3 size = 1 - Size of the bounding box. Within it an expression is executed (valid only the expression-transformed child object is outside the view frustum). This is an optional argument.
variable call (string name)
Calls a world expression function from any other script.Arguments
- string name - World expression node name.
Return value
Variable returned by the called expression function.variable call (string name, variable arg0)
Calls a one-argument world expression function from any other script.Arguments
- string name - World expression node name.
- variable arg0 - Argument for the called function.
Return value
Variable returned by the called expression function.variable call (string name, variable arg0, variable arg1)
Calls a two-argument world expression function from any other script.Arguments
- string name - World expression node name.
- variable arg0 - The first argument for the called function.
- variable arg1 - The second argument for the called function.
Return value
Variable returned by the called expression function.variable call (string name, variable arg0, variable arg1, variable arg2)
Calls a three-argument world expression function from any other script.Arguments
- string name - World expression node name.
- variable arg0 - The first argument for the called function.
- variable arg1 - The second argument for the called function.
- variable arg2 - The third argument for the called function.
Return value
Variable returned by the called expression function.variable call (string name, variable arg0, variable arg1, variable arg2, variable arg3)
Calls a four-argument world expression function from any other script.Arguments
- string name - World expression node name.
- variable arg0 - The first argument for the called function.
- variable arg1 - The second argument for the called function.
- variable arg2 - The third argument for the called function.
- variable arg3 - The fourth argument for the called function.
Return value
Variable returned by the called expression function.string getExpression ()
Returns the executable expression.Return value
Executable expression.vec3 getOffset ()
Returns the current coordinates of the expression box center.Return value
Expression box center coordinates.vec3 getSize ()
Returns the current size of the bounding box within which expression is executed (valid only outside the view frustum). If the child object transformed according to the expression gets outside the view frustum, but stays within the Size range, the playback of the transformation sequence does not stop.Return value
Size of the bounding box in units.int isCompiled ()
Returns a value indicating if the given expression has been compiled. (It is automatically called on world load or after setExpression() is used.)Return value
1 if the expression has been compiled; otherwise, 0.int setExpression (string src)
Sets the arbitrary expression to be executed.Arguments
- string src - Executable expression.
Return value
Expression number.void setOffset (vec3 offset)
Sets coordinates of the expression box center.Arguments
- vec3 offset - Expression box center coordinates.
void setSize (vec3 size)
Sets the size of the bounding box within which expression is executed (valid only outside the view frustum). If the child object transformed according to the expression gets outside the view frustum, but stays within the Size range, the playback of the transformation sequence does not stop.Arguments
- vec3 size - Size of the bounding box in units.
Last update: 03.07.2017
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter