The MacroMaker |
The MacroMaker is an interactive tool to help you create new nodes by recombining previously existing nodes. Shake's scripting language is basically C-like, meaning you have access to an entire programming language to manipulate your scripts. Because the MacroMaker can't account for all possibilities, you should think of the MacroMaker as a tool for helping you get started in using Shake's language. Use the MacroMaker to build the initial files, and then modify these files to customize your macros.
The macro tutorial,
is highly recommended, as it gives you a better understanding of what exactly
the MacroMaker is doing.
You should first create your node structure of what you want to occur in the node. This can be very simple or very complex. To illustrate macro building, create a function that randomly scales, pans, and rotates your image, similar to CameraShake, but with more parameters moving.
Parameter
|
Value
|
xPan | (turbulence(time,2)-.5)*20 |
yPan | (turbulence(time+100,2)-.5)*20 |
angle | (turbulence(time+200,2)-.5)*10 |
xScale | turbulence(time+300,2)/2+.75 |
In these examples, the turbulence function generates continual noise between 0 and 1 (see Expressions). Since you don't want all fluctuations to have the same pattern, offset the seed each time you call the function (time, time+100, time+200, time+300). Then simple math is used to get the values in an appropriate range. For example, in angle, .5 is subtracted to get it in a range of -.5 to .5, and then the result is multiplied by 10, giving a range between -5 and 5 degrees of rotation.
Now that you have something that is a tedious to re-create all of the time, it seems like a good idea to make a macro.
The top part of the window controls where the file is saved, its name, and
where it appears:
Parameter
|
Value
|
Macro Name
|
This, surprisingly, is the name of the macro you make. It is also the name of the file you are saving (see below). |
Macro Toolbox
|
This is the Tool tab that gets the macro. If a tab does not exist, it creates a new one. |
Store Macro in:
|
User directory: This saves the macro in your <UserDirectory>/nreal/include/startup as MacroName.h and a second ui file in <UserDirectory>/nreal/include/startup/ui as MacroNameUI.h. Shake Directory: This saves your macro in the Shake distribution directory, as <ShakeDir>/include/startup/MacroName.h and <ShakeDir>/include/startup/ui/MacroNameUI.h. See Customize Shake for more details on these directories and their functions. |
Macro's output is:
|
This presents a list of all nodes that are included in the Macro (just one if you are doing the Move2D example). Select the node that you want to see passed out of the macro. Shake usually does a correct guess of what this node should be if you have only one terminating branch. |
The bottom part of the window is the list of all nodes and the
parameters you can expose. For example, since the image is being fed into
Move2D, the image In parameter has been turned on with the Status
light.
Parameter
|
Value
|
Parameter name
|
This is the name of either the slider (in the case of float and int values) or the knot input (in the case of image inputs). Arbitrarily renaming your parameters is not recommended (that is, dufusHead), as you have the benefit of Shake's default GUI behaviors (popup menus, subtrees, color pickers, on/off switches, etc.) if they have the same name. |
Default value
|
All current values of the nodes are fed into text fields. If you want to set a default value for exposed parameters (that is, ones that have the visible Status light on), you can set that here. |
Status
|
Turn this on to expose this parameter. If you expose an image, it will add a knot to the top of the node. If you expose anything else, it will give you a slider or textfield in the Parameter View. |
Minimum
|
For slider-based parameters, this sets the lower slider limit. |
Maximum
|
For slider-based parameters, this sets the upper slider limit. |
Granularity
|
This sets how much the slider jumps between values. |
Since you already have the most of the parameters you need in this example, the only ones you would really want to expose are the motionBlur, shutterTiming, and shutterOffset values.
Press OK, and the macro is created.
In the startup directory, you should see a new file. If you followed the instructions, the file is named RandomMove.h.
image RandomMove( image In=0, float motionBlur=0, float shutterTiming=0.5, float shutterOffset=0 ) { Move2D1 = Move2D( In, (turbulence(time,2)-.5)*20, (turbulence(time+100,2)-.5)*20, (turbulence(time+200,2)-.5)*10, 1, turbulence(time+300,2)/2+.75, xScale, 0, 0, width/2, height/2, "default", xFilter, "trsx", 0, motionBlur, shutterTiming, shutterOffset, 0, ); return Move2D1; }
Edit the macro in this file. You can see that the parameters motionBlur, shutterTiming, and shutterOffset are declared in the first few lines, and then assigned default values. The image input In is also assigned a value of 0, meaning there is no expected image input when the macro is created.
image RandomMove( image In=0, float motionBlur=0, float shutterTiming=0.5, float shutterOffset=0 ) ...
Modify the behavior of the macro. Each turbulence function has a frequency of 2 in it, i.e., turbulence(time,2). Create a new parameter to modify the frequency.
image RandomMove( image In=0, float frequency = 2, float motionBlur=0, float shutterTiming=0.5, float shutterOffset=0 ) ...
Now that you have a new parameter, you must substitute it into the macro body wherever you want that value to apply.
image RandomMove( image In=0, float frequency = 2, float motionBlur=0, float shutterTiming=0.5, float shutterOffset=0 ) { Move2D1 = Move2D( In, (turbulence(time,frequency)-.5)*20, (turbulence(time+100,frequency)-.5)*20, (turbulence(time+200,frequency)-.5)*10, 1, turbulence(time+300,frequency)/2+.75, xScale, 0, 0, ...
Save the macro file
Re-launch Shake to see the modifications.
The macro file in the startup directory merely creates the function. The interface gets built by Shake each time it is launched. Therefore, the MacroMaker also creates a second file in the startup/ui subdirectory that creates a button and sets slider ranges for the node. For example, if you created the new frequency slider in the above example, you may have noticed that the slider only goes from 0 to 1. You can modify this in the ui file.
nuiPushMenu("Tools"); nuiPushToolBox("Transform"); nuiToolBoxItem("@RandomMove",RandomMove()); nuiPopToolBox(); nuiPopMenu(); nuiDefSlider("RandomMove.motionBlur",0,1,0,0,0); nuiDefSlider("RandomMove.shutterTiming",0,2,0,0,0.01); nuiDefSlider("RandomMove.shutterOffset",-1,1,0,0,0.01);
The first line opens the Tools tabs. The second line opens the Transform tab. To place the macro in a different tab, change the word Transform to a different name. The third line creates the button. The first occurrence of the word RandomMove is preceded by an @ sign, indicating that there is no icon (no relation at all with Shake's unpadded frame wildcard) for the button, so therefore the text RandomMove should be printed on the button. The second listing of the word RandomMove is the function that gets called when you press the button. Because you have default arguments already supplied in the macro, you don't need to supply any arguments, they would go between the parentheses: (). The last lines are basically saying "For the RandomMove function, set the slider ranges for the shutterOffset parameter between -1 and 1, with some extra granularity settings". Since this sets the slider range, we can copy it and adapt it for the new frequency parameter.
... nuiDefSlider("RandomMove.shutterTiming",0,2,0,0,0.01); nuiDefSlider("RandomMove.shutterOffset",-1,1,0,0,0.01); nuiDefSlider("RandomMove.frequency",0,10,0,0,0.01);
To add an icon to the button, do the following steps:
Create a 75x40 pixel image in Shake.
Strip out the Alpha channel, which can be done with a SetAlpha node with a value of 0.
Set the FileOut to your <UserDirectory>/nreal//icons directory, naming it TabName.Name.nri. In the above example, it would be called Transform.RandomMove.nri.
Render the file.
In the RandomMoveUI.h file, remove the @ sign on line 3.
Save the text file.
Relaunch Shake, and RandomMove has an icon.
In all cases of the above code, case sensitivity is important. If the macro name is all caps, then all occurrences of the name must also be all caps. The same restriction applies to parameter and icons names.
For more information on customizing Shake, jump to Customize Shake and Scripts - Attaching Parameter Widgets.