Mewa User's Guide/Mewa Script Programming
Language Reference
editMewa 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
editAll 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:
myString = "Hello";
if Conditionals
editif(x == 0)
{
print('Zero')
}
else
{
print('Non zero')
}
while Loops
editwhile( download.inProgress() ) {
dialog.setProgress( download.progress() );
}
do-while Loops
editi=0;
do {
// ...
i+=1;
} while( i < 3 );
Functions
editBelow 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 )
editAdds 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:
connectNodes("ColorWheel", "OverlayBlend", 0);
delete( var1, var2, ... )
editdelete 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.
myNode = ColorWheelNode();
delete( myNode );
Because the myNode is internally referenced (owned) by the nodegraph the myNode variable is deleted but the node is not.
deleteAll()
editDeletes 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 #delete().
nodegraph()
editReturns the #Nodegraph object.
Classes
editColorWheelNode
editCreates a new ColorWheel node and adds it to the node-graph.
Constructors
edit- 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.
Dialog
editContructors
edit- Dialog( text )
- Dialog( text , title )
Creates and shows a Dialog with text. The title argument is optional.
Example:
dialog = Dialog("Do you wish to continue?");
dialog.addButton("Continue"); // button 0
dialog.addButton("Cancel"); // button 1
clickedOption = dialog.wait();
if( clickedOption == 1 ) { // if clicked cancel button
dialog.close();
return;
}
dialog.setText("Downloading update...");
clickedOption = dialog.wait();
addButton( text )
editdialog = Dialog("Do you wish to continue?");
dialog.addButton("Continue");
dialog.addButton("Cancel");
clickedOption = dialog.wait(); // returns the button index when clicked
if( clickedOption == 1 ) { // clicked cancel button
dialog.close();
return;
}
addButton( text, functionHandler )
editExample:
function onOkButton()
{
dialog.close();
}
dialog = Dialog("Downloading update...");
dialog.addButton( "Ok", onOkButton );
setProgress( percent )
editProgress 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 )
editset empty text to hide
setText( text )
editset empty text to hide
wait()
editReturns only when a button is clicked. The returned value is the index of the clicked button.
close()
editCloses and hides the dialog.
Dir
editcd( dirName )
editEnters directory dirName. Returns true if successfull.
exists( name )
editname is a file or directory name. Returns true if file/dir exists.
size( name )
editReturns the file size of the given file name. Returns -1 if the file does not exist.
delete( name )
editDeletes the file or directory with given name.
makeDir( name )
editDownload
editContructors:
- Download( dir, url )
Starts a downloads the specified url to the given dir.
progress()
editReturns the downloaded data size in bytes.
status()
editReturn an integer, that can be either 1, 2 or 3:
- in progress
- completed
- failed
cancel()
editCancels the running download.
FootageNode
editConstructors
edit- 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.
node = FootageNode( "C:\MyVideos\sun.mp4" );
See also Node class.
Move2DNode
editConstructors
edit- 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
editThe nodegraph() function returns a Nodegraph object.
setTranslation( x, y )
editTranslates the node-graph view to position x,y.
Node
editNode is the base class for all Mewa nodes, like #FootageNode and #ShaderNode.
setName( name )
editSets 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.
setPos( x, y )
editsetHelpPage( url )
edit[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.
ShaderNode
editConstructors
edit- 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 #addFloatControl, #addVec2Control and #addColorControl. Each of those functions adds one row to the node's panel, starting from the bottom.
Controls
editControls are graphical widgets used to change the value of input variables in the shader program. There are 3 different control types:
- #addFloatControl connects to a input variable of type float
- #addVec2Control connects to a input variable of type vec2
- #addColorControl 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 )
editAdds 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 #FloatControl object.
addVec2Control( variableName, defaultValues )
editaddColorControl( variableName )
editThis function creates a #ColorControl connected to variable with name variableName and initialized with black color (0,0,0). See more at #ColorControl.
addColorControl( variableName, gray )
editgray argument is a number. This function creates a #ColorControl 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 )
editThe color control has 3 parameters. Clicking on the color button expands to show the 3 parameters.
setRenderArea( area )
editThe 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 )
editOptions are Nearest, Linear or Mipmap
setWrap( channel, filter )
editOptions are Clamp or Repeat.
setFlip( channel, filter )
editOptions are NoFlip, HorizontalFlip or VerticalFlip.
ColorControl
editCreate a color control initialized with red color. uColor is the name of the vec3 uniform variable in the glsl shader code.
parameter = node.addColorControl("uColor", 0.8, 0.2, 0.2 );
Color control has 3 parameters, one for each color channel.
setName( name )
editSets the name of this control. name is shown in the control as a text label.
See also Controls section.
FloatControl
editThe 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.
parameter = node.addFloatControl("uDelta", 2.5);
parameter.setName("Delta");
parameter.setStep(0.01);
parameter.setRange(-2, 7);
setRange( min, max )
editSets 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 )
editAdjust the step value to make a parameter increase faster or slower with the mouse movement.
setName( name )
editSets 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.
Vec2Control
editsetName( name )
editSets the name of this control. name is shown in the control as a text label.
See also #Controls.