USC Interpreter
The stand-alone interpreter (called USC due to its script file extension) allows for making Unigine scripts into executable programs that are run directly from the environment or from the command-line. As the interpreter works independently, it offers an easy way for developers to extend the functionality and solve the specific or recurring tasks for which it is not necessary to create a separate executable application.
Source code of the stand-alone interpreter can be found under <UnigineSDK>/source/tools/Interpreter.
What Can It Be Used for?
Core library | The stand-alone interpreter includes the Core library and can be used to read/write files, parse XML files, handle images, perform mathematical calculations, etc. |
---|---|
Meshes | Load and save a mesh, modify or clear all its data. You can add and set transformation to mesh surfaces, as well as change position, normal vectors and texture coordinates for separate vertices. |
Skinned meshes | Just like in case with simple meshes, you can get access and modify surface and vertex data for skinned meshes. Data on bones of the rig is also exposed. |
Command line arguments | Pass any number of arguments to the executable script via the command line. (See examples below.) |
Logging | Print notify messages, warnings and errors to track progress of script execution, if necessary. |
How to Run USC
Running USC on Windows
To use Interpreter on Windows, follow these steps:
- Create a script to be executed and save it with *.usc extension.
- Associate usc files with <UnigineSDK>/bin/usc_*.exe. Depending on the postfix, it can be either 32-bit (_86) or 64-bit, debug (d) or release (no postfix) version of the Interpreter.
Running USC on Linux or Mac OS X
To use Interpreter on Linux or Mac OS X, follow these steps:
- Add a path to <UnigineSDK>/bin/usc_*.exe to environment variables. Depending on the postfix, you can use either 32-bit (_86) or 64-bit, debug (d) or release (no postfix) version of the Interpreter.
- In the first line line of your script, use the following:
#!/usr/bin/env usc
How to Create USC Script
To create USC script (written in UnigineScript), use main() function as an entry point:
void main()
{
// Code
}
Below are given examples how to pass command-line arguments to the USC script.
Example 1. Printing All Command-line Arguments
#!/usr/bin/env usc
/*
*/
void main() {
forloop(int i = 0; getNumArgs()) {
log.message("Arg [%d]: %s\n",i,getArg(i));
}
}
Example 2. Setting Variables Passed via the Command Line
#!/usr/bin/env usc
int value1 = 0;
int value2 = 0;
/*
*/
void main() {
for(int i = 0; i < getNumArgs(); i++) {
string arg = getArg(i);
if(arg == "-set_value_1") {
if(i + 1 >= getNumArgs()) {
continue;
}
value1 = int(getArg(++i));
continue;
}
if(arg == "-set_value_2") {
if(i + 1 >= getNumArgs()) {
continue;
}
value2 = int(getArg(++i));
continue;
}
}
log.message("value1: %d\nvalue2: %d\n",value1,value2);
}