Project 11.2: Marking Menus a Go-Go


Project 11.2: Marking Menus a Go-Go

While the Marking Menu Editor should always be the fist place a user , even a MEL-savvy one, should go to create and edit new Marking menus, it is often necessary to go to the original source script files to alter the behavior of the Marking menus that exist within Maya by default.

Maya creates an amazingly large variety of Marking menus based on the same action, the press of the right mouse button. Upon pressing, Maya goes through a complicated series of actions, all to determine what items need to be in the Marking menu, builds the menu, and shows it to the user. All of these actions are contained in a script in the MayaX.X/scripts/others directory called dagMenuProc.mel .

Finding the appropriate file to modify when we want to change the behavior of an AliasWavefront script can sometimes be challenging. If we include all the scripts that make up a default installation of Maya, there are more than 2300 separate script files, many with multiple procedures, to wade through. It is often a matter of some simple detective work to find the correct file and procedure. If the Script Editor echoes the name of the procedure, simply look for a .mel file of the same name. If that yields no results, using either your operating system s search capabilities or some data mining software to search for the procedure name in the body of all the scripts will often find the appropriate file. If this still yields no results, then the command might be one of the few hard-coded commands that exist in Maya. It is good practice to keep a journal file or log of what each procedure does as it is discovered . For example, the dagMenuProc.mel file was discovered accidentally after looking for the scripts associated with the modeling views. This led to looking at ModEdMenu.mel , which led to buildObjectMenuItemsNow.mel , which in turn led to dagMenuProc.mel . Having kept track of these relationships lets us quickly find the appropriate files when we do want to change the behavior defined therein.

What we want to do is add functionality to the Marking menu that appears when a user right-clicks over a joint. By default, all that appears are two commands associated more with skinning than with skeleton construction, Assume Preferred Angle and Set Preferred Angle, as seen in Figure 11.15.

click to expand
Figure 11.15: The default Marking menu for joints in Maya.

One of the attributes unique to joints is jointOrient . Serving as a rotational offset for its parent, jointOrient is incredibly useful for positioning a bone and keeping its rotation values at 0, similar to Freeze Transform.

Design

The script to reset the joint orientations is quite simple, the type of script MEL-savvy artists write every day to aid in their workflow. Example 11.13 shows the script text.

Example 11.13: The script to reset joint rotation values.

 global proc int resetJointRotations (string $joint)     {  // Find the rotation values of the joint  float $rx = `getAttr ($joint + ".rotateX")`;      float $ry = `getAttr ($joint + ".rotateY")`;      float $rz = `getAttr ($joint + ".rotateZ")`;  // Find the joint orient values for the joint  float $jox = `getAttr ($joint + ".jointOrientX")`;      float $joy = `getAttr ($joint + ".jointOrientY")`;      float $joz = `getAttr ($joint + ".jointOrientZ")`;  // Reset the rotation values to 0  setAttr ($joint + ".rotateX") 0 ;      setAttr ($joint + ".rotateY") 0 ;      setAttr ($joint + ".rotateZ") 0 ;  // Set the joint orients to their new value  setAttr ($joint + ".jointOrientX") ($jox + $rx);      setAttr ($joint + ".jointOrientY") ($joy + $ry);      setAttr ($joint + ".jointOrientZ") ($joz + $rz);     return 1;     } 
On the CD  

The text for this script is found on the CD-ROM as Chapter_11/project_UI05/resetJointRotations.mel

Now that the command exists to accomplish what we want, we can add it to the Marking menu that appears when a user right-clicks on a joint. After making a backup of the file, open the dagMenuProc.mel file found in the ../others/ directory.

The file is quite large, and finding the appropriate section of such files can sometimes be a daunting task. However, in this case, we can simply use the Find capabilities of a text editor to search for the phrase Set Preferred Angle, which finds the section that builds the Marking menu for right-click over a joint. Part of an enormous if-else if statement, the appropriate section is seen in Example 11.14.

Example 11.14: The code that defines the Marking menu for joints.

 . . .     else if ($isJointObject) {         menuItem -l "Set Preferred Angle"             -echoCommand true             -c (`performSetPrefAngle 2` + " " + $item)             -rp "W"             setPrefAngleItem;         menuItem -l "Assume Preferred Angle"             -echoCommand true             -c (`performAssumePrefAngle 2` + " " + $item)             -rp "E"             assumePrefAngleItem;  // Check if the current context is the skinPaint context   // and the the joint is connected to a skinCluster  

Following the comment is a more intense section that checks to see if the user has the Paint Weights tool (termed a context in Maya programming) selected, and if so places a Paint Weights item in the north quadrant of the Marking menu. This means we have five remaining areas in which to place our tool. For our example, we will use the southwest corner. We add the section shown in Example 11.15 to dagMenuProc.mel to add the menu. Note the commenting added to easily find the user added section.

Example 11.15: The code we added to modify.

 . . .     else if ($isJointObject) {         menuItem -l "Set Preferred Angle"             -echoCommand true             -c (`performSetPrefAngle 2` + " " + $item)             -rp "W"             setPrefAngleItem;         menuItem -l "Assume Preferred Angle"             -echoCommand true             -c (`performAssumePrefAngle 2` + " " + $item)             -rp "E"             assumePrefAngleItem;         //**********************************************         //  //        USER ADDED SECTION  //         //**********************************************  // The following adds resetJointRotations to the   // context sensitive joint marking menu   // added on 19.October.2002  menuItem             -label "Reset Joint Rotations"             -echoCommand true             -command ("resetJointRotations " + $item)             -rp "SW"             resetJointRotationsItem;  // Check if the current context is the skinPaint context  
On the CD  

The text for this script is found on the CD-ROM as Chapter_11/project_UI05/dagMenuProc.additions

To see the results of this, we have to source the dagMenuProc.mel file, or start a new Maya session. After this is done, we get the menu pictured in Figure 11.16.

click to expand
Figure 11.16: The addition to the Marking menu now appears.

Now that we can customize the context-sensitive marking menus, we have an amazing amount of control over the way a user interacts with objects in the Maya interface. We can confidently modify the scripts defining the marking menus defined by the scripts in the ../startup and ../other directories. Remember to always back up these files, to ensure that any problems can be easily fixed.

Panels

For all the time we have spent discussing UI elements such as layouts and controls, it is interesting to realize that the vast majority of the user interface is actually made up of panels. Panels make up the Channel Box, the Outliner, the Graph Editor ”even the Modeling views. Once we are able to access panels, we can create more intelligent hotkeys and hotkey behavior, and incorporate them into our own UIs. Finally, we will learn about the power of a family of panels called scripted panels .

Looking at a list of the panels available in Maya is almost like looking at the list of editors available to the Maya artist. Some panel types include:

  • componentEditor

  • hyperShade

  • outlinerPanel

  • modelPanel

  • hardwareRenderPanel

  • visor

  • hyperGraph

Looking at that list, we see that nearly every part of the interface we use to work with data in Maya is handled by panel constructs. If we can access these panels from MEL, we suddenly gain control over the vast majority of the interface.

There are two pieces of information we need to gather when working with panels that, while similar, result in vastly different behavior. Those two pieces of information are the panel with focus and the panel under .

If we refer to Figure 11.17, we see that the Modeling view has a darkened border. This represents the panel with focus. The easy definition of focus is that it is the last panel the user was working in, or clicked in. The other way to find which panel the user intends to work in is to find which panel is underneath the pointer. In Figure 11.18, although the outliner has focus, the Graph Editor is currently under the pointer.

click to expand
Figure 11.17: A Modeling panel with focus.
click to expand
Figure 11.18: The difference between focus and under pointer status of panels.

We access both of these qualities with the command getPanel . With getPanel , we can gather a variety of data from the operating environment. We will be using some of its other arguments later when we begin to work with scripted panels. Now that we can find what panel is active, we can begin to do something with that information.

Within Maya are a number of options that are available to customize and tweak the appearance of the modeling windows . One of the more recent additions was the ability to activate a mode called Isolate Select. Isolate Select allows an artist to hide any unselected objects, but only in a particular viewport, rather than as a global visibility change. Creating a single hotkey that toggles the isolate select state of a window is a simple matter of finding which window the user wants to isolate in, and use a simple if-else conditional statement to set the state based on its current status. Simple for any artist to do, with a little MEL knowledge. Hotkey assignments can have MEL commands entered directly in them, as is seen in Figure 11.19.

click to expand
Figure 11.19: Entering code into the Hotkey Editor.

The actual code is, as stated, simple, and seen in Example 11.16.

Example 11.16: The code to change the Isolate Select hotkey into a toggle.

 $aPanel = `getPanel -withFocus`;     $isoStatus = `modelEditor             -query viewSelected             $aPanel`;     if ($isoStatus == 0)         {         enableIsolateSelect $aPanel 1;         isolateSelect -state on $aPanel;         }     else         {         enableIsolateSelect $aPanel 0;         isolateSelect -state off $aPanel;         } 

Similarly, a single hotkey could be used to toggle between shading types, shadows, or even the tessellation of NURBS objects replacing the 1, 2, and 3 keys by simply pressing “ or + to increase detail as wanted.

Panels can also be easily inserted into UIs created by the user. Note that many of the panel types are actually scripted panels, which follow a different set of rules, which we will get to later. In our next UI project, we will explore how to insert a modeling panel into a user window.




The MEL Companion
The MEL Companion: Maya Scripting for 3D Artists (Charles River Media Graphics)
ISBN: 1584502754
EAN: 2147483647
Year: 2003
Pages: 101

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net