User MEL Scripts brush settings

These options appear as a subset of the Tubes section in the Paint Effects Brush Settings window, and the Attribute Editor for any brush node.

You can write MEL scripts that apply effects during the growth simulation of the brush. There are two types of scripts: creation and runtime.

Typically, you’ll want to modify the sample scripts provided in the Maya scripts directory as follows:

  1. Copy the MEL file for the desired function from the Maya scripts directory:

    (Windows and Linux) mayapath/scripts/paintEffects

    (Mac OS X) mayapath/Maya/Contents/scripts/paintEffects

  2. Paste the file to your local scripts directory and rename it.
  3. Modify the function. Change the function name to match the file name prefix (for example, leafDroop). Do not modify the declaration of the function (its list of input arguments).
Creation Script

Creation scripts override the normal tube creation routine, and therefore many of the controls. The following sample creation script is provided in your Maya scripts directory:

  • paintCreateFunc.mel – Mimics normal tube creation.
Runtime Script

Runtime scripts are called every time a new segment is added to a tube. Typically, most things you want to do use runtime scripts. The following sample runtime scripts are provided in your Maya scripts directory:

  • paintRuntimeFunc.mel – Creates two leaves at the base of the tubes and applies a random wiggle.
  • paintCollideFunc.mel – Collides the tubes with a two unit sphere placed at 0, 1, 0. You could use this function to create a new function that binds the position of the sphere to some object in the scene.
  • leafDroop.mel – Makes all the leaves droop downwards. You could make the gravity on a tree negative so that the tree always grows upwards, yet has the leaves growing downwards. (If you are not generating secondary branches, this function is the simplest one to use as a template for new functions.)
  • widthNoise.mel - Makes the width along a tube vary in a random manner. It only affects base tubes and twigs, not leaves or flowers.
    Note: Creation scripts do not work as runtime scripts, and vice versa.

    When you use a runtime function, wireframe redraw may be slower for complex objects because the function is called for every tube segment.

Runtime callbacks

You can use the stroke or brush name to tailor the Runtime procedure based on the name.

Custom Paint Effects brushes that use callback functions must have two arguments at the end of all of callback procedure definitions: the brush and the stroke name. These arguments allow you to know the name of the brush, and the name of the stroke that has triggered the callback.

These callback arguments are present in the example scripts (for example <maya_home>/scripts/paintEffects/leafDroop.mel).

In order to exercise a Runtime callback, you can do the following:

  1. Copy <maya_home>/scripts/paintEffects/leafDroop.mel to <maya_home>/scripts/startup.
  2. Add a print("brushName="+$brushName+"\n"); statement somewhere inside the callback in leafDroop.mel.
  3. In the Maya Modeling menu set, select Generate > Paint Effects Tool, and then Generate > Template Brush Settings.
  4. In the Paint Effects Brush Settings window, click Tubes.
  5. Select the Tubes check box.
  6. Click User MEL scripts.
  7. in the Runtime Script text area, type leafDroop.
  8. In the Maya scene view, draw some Paint Effects strokes, and you should see that the leafDroop procedure is called.