Mewa User's Guide/Mewa Script Programming

Language Reference
Mewa programming language, although resembling a lot like javascript, does not follow any programming language specfication. It was designed to answer Mewa application requirements on performance and ease of use. The language syntax might change in order to match future quirements or users preferences.

Data Types
All numbers in Mewa are stored as floating-point.

Booleans true and false are stored as numbers 1.0 and 0.0.

Strings are represented by text within quotation marks, as shown below:

Functions
Below is a list of all functions supported by Mewa scripting.

If you need a function that is currently not available please contact us, we want to help you.

connectNodes( outNodeName, inNodeName, inputIndex )
Adds a connection between output of node with name outNodeName and input of node with name inNodeName. inputIndex is the index of the input port. Node input ports are indexed from 0 to N, where N is the number of input ports. In other words, the first input port of a node has index 0, the second input has index 1, and so on.

Example:

delete( var1, var2, ... )
delete function deletes variables. Accepts as input arguments a list of variables names.

The example below creates a node and then deletes the variable referencing the node. The data referenced by a variable is only deleted if the data is not referenced anywhere else. Because the myNode is internally referenced (owned) by the nodegraph the myNode variable is deleted but the node is not.

deleteAll
Deletes all set variables.

Note that deleting a variable does not necessarily delete the data referenced by the variable. The data referenced by the variable is only deleted if not referenced anywhere else.

See also.

nodegraph
Returns the object.

ColorWheelNode
Creates a new ColorWheel node and adds it to the node-graph.

Constructors

 * ColorWheelNode
 * ColorWheelNode( name, pos )

The constructor ColorWheelNode adds a new ColorWheel node to the node-graph. The name and position of the node are automatically filled.

The constructor ColorWheelNode( name, pos ) adds a new ColorWheel node to the node-graph with the given name and at given pos. This constructor is used to save and restore a node-graph.

Contructors

 * Dialog( text )
 * Dialog( text, title )

Creates and shows a Dialog with text. The title argument is optional.

Example:

addButton( text, functionHandler )
Example:

setProgress( percent )
Progress value needs to be between 0 and 1. To hide the progress bar set a negative value (< 0). To show a running progress set a value bigger than 1 (> 1).

setTitle( title )
set empty text to hide

setText( text )
set empty text to hide

wait
Returns only when a button is clicked. The returned value is the index of the clicked button.

close
Closes and hides the dialog.

cd( dirName )
Enters directory dirName. Returns true if successfull.

exists( name )
name is a file or directory name. Returns true if file/dir exists.

size( name )
Returns the file size of the given file name. Returns -1 if the file does not exist.

delete( name )
Deletes the file or directory with given name.

Download
Contructors:
 * Download( dir, url )

Starts a downloads the specified url to the given dir.

progress
Returns the downloaded data size in bytes.

status
Return an integer, that can be either 1, 2 or 3:
 * 1) in progress
 * 2) completed
 * 3) failed

cancel
Cancels the running download.

Constructors

 * FootageNode( source )
 * FootageNode( source, pos, name )

source is a video filename or a list of filenames of images (image sequence). pos is a vector with 2 numbers.

See also Node class.

Constructors

 * Move2DNode
 * Move2DNode( name, pos )

The constructor Move2DNode adds a new Move2D node to the node-graph. The name and position of the node are automatically filled.

The constructor Move2DNode( name, pos ) adds a new Move2D node to the node-graph with the given name and at given pos. This constructor is used to save and restore a node-graph.

Nodegraph
The nodegraph function returns a Nodegraph object.

setTranslation( x, y )
Translates the node-graph view to position x,y.

Node
Node is the base class for all Mewa nodes, like and.

setName( name )
Sets the given name to the node. If the name already exist, a number is added at the end of the name in order to make it unique.

setHelpPage( url )
[panel image]

Use this function associate a help page to a node. The help page is url link. The link is opened in the system web browser when the user clicks [help button] located at the top of node parameters window.

Constructors

 * ShaderNode( glslCode, nameHint )
 * ShaderNode( glslCode, name, pos )

Adds node to the node-graph.

nameHint is the name given to the node while generating a unique name for the node. If there is already a node with name nameHint a number will be added at the end of the nameHint to make it unique.

If pos is not provided the node will be placed at a "best guess" position.

The best way to learn on how to create shader nodes is to look at examples. Mewa web store provides many scripts with it's source available. One example is Ether

To fill the node's panel use the functions, and. Each of those functions adds one row to the node's panel, starting from the bottom.

Controls
Controls are graphical widgets used to change the value of input variables in the shader program. There are 3 different control types:
 * connects to a input variable of type float
 * connects to a input variable of type vec2
 * connects to a input variable of type vec3

By default the controls will show the name of the variable as a text label. The label text can be modified by through the function:
 * setName( name )

The control name should be unique within the node as the name can be used in the control search.

addFloatControl( variableName, defaultValue )
Adds a GUI control to the node [Mewa_User%27s_Guide/Using_the_Node_Graph | node panel] to change the value of a given variable in the shader program.

variableName is the name of variable in the shader source that will be controlled.



Returns a object.

addColorControl( variableName )
This function creates a connected to variable with name variableName and initialized with black color (0,0,0). See more at.

addColorControl( variableName, gray )
gray argument is a number. This function creates a connected to variable with name variableName and initialized with gray value set on the three channels R,G and B.

addColorControl( variableName, red, green, blue )
The color control has 3 parameters. Clicking on the color button expands to show the 3 parameters.

setRenderArea( area )
The input should be "iResolution", "iChannel0" or "iChannel0+iChannel1".




 * setRenderArea("iResolution") An example of a node using setRenderArea("iResolution") is Ether. This example uses the input coordinates passed into fragCoord in mainImage( out vec4 fragColor, in vec2 fragCoord ) to generate a procedural image. Because "iResolution" option fills the entire viewport using fragCoord values that go always from 0 to 1, this option is mostly used to generate images.
 * setRenderArea("iChannel0") An example of a node using setRenderArea("iChannel0") is HexPixelate. The iChannel0 option automatically adds an input port to the node. to connect an input image. The input coordinates fragCoord passed into mainImage( out vec4 fragColor, in vec2 fragCoord ) cover only the input image. Also, note that fragCoord coordinates can have any range of values within the 0 to 1 limits. Use the texture size in variable iChannelResolution[0] to get, always, a 0 to 1 range in the fragCoord input variable. The iChannel0 option is aminly aimed at the creation of image processing nodes, taking an input image for processing and outputing the result.
 * setRenderArea("iChannel0+iChannel1") An example using setRenderArea("iChannel0+iChannel1") can be found in OverlayBlend. This option is mostly used to merge 2 images. It adds 2 input ports to the node. When using the iChannel0+iChannel1 option make sure to be use mainImage( out vec4 fragColor, in vec2 fragCoordA, in vec2 fragCoordB ) function in your shader source to access the texture coordinates of both images. Use the texture size in variable iChannelResolution[0] to get, always, a 0 to 1 range in the fragCoord input variable.

setFilter( channel, filter )
Options are Nearest, Linear or Mipmap

setWrap( channel, filter )
Options are Clamp or Repeat.

setFlip( channel, filter )
Options are NoFlip, HorizontalFlip or VerticalFlip.

ColorControl


Create a color control initialized with red color. uColor is the name of the vec3 uniform variable in the glsl shader code.

Color control has 3 parameters, one for each color channel.

setName( name )
Sets the name of this control. name is shown in the control as a text label.

See also Controls section.

FloatControl
The code below, taken from Ether.mw, shows how a FloatControl is used. The function addFloatControl creates a control, adds it to the node panel and returns the control for further setup.

setRange( min, max )
Sets a minimum and maximum value a parameter can have. To disable min and max, letting the UI control to reach any value set the same value for min and max (min == max).

setStep( increment )
Adjust the step value to make a parameter increase faster or slower with the mouse movement.

setName( name )
Sets the name of this control. name is shown in the control as a text label.

The control name should be unique within the node as the name can be used in the control search.

setName( name )
Sets the name of this control. name is shown in the control as a text label.

See also.