Project 11.5: Heads Up


Project 11.5: Heads Up!

Because HUDs are constantly on screen, they often serve to give feedback on scene information, either the scene or a selected object. Although most often associated with artists working with polygons, often games artists, to keep assets within pre-defined limitations on geometry, artists working with other types of geometry can benefit from using HUDs. In this project we will construct a HUD to track some of the more pertinent information needed by artists working with NURBs surfaces.

It is sometimes interesting to watch an artist work with a model constructed of NURBs geometry. Constantly opening and closing the Attribute Editor to check the number of spans , the degree of curvature, and other such information needed to properly construct adjacent surfaces is tedious for any artist. Rather than having to surrender screen real estate to the Attribute Editor, we will give NURBs artists the HUD tools their polygon-using brethren have.

Design

We will track four different aspects of NURBs surfaces:

  • U Spans

  • V Spans

  • U Degree

  • V Degree

And two different aspects of NURBs curves:

  • Spans

  • Degree

We will rebuild the HUD whenever the selection changes, as well as whenever the appropriate attributes change. In addition, when the user has no valid object selected, the HUD will have to accommodate this. Moreover, unlike the polygon HUD, we are not interested in data that can be summed up, such as the number of polygons in the current selection; rather, we have to pick which of the selected objects to use. How do we account for multiple NURBs objects being selected? If we use the last selection, do we simply use the last selection, or do we use the last NURBs object selected? For simplicity, we will only consider the last item selected in our script. If that is a NURBs curve or surface, our HUD will evaluate it; otherwise , it will display - . We will have to generate a single procedure that both evaluates the selection and returns the appropriate info . This script,  nurbsInfo.mel is found on the companion CD-ROM under /chapter11/scripts/others/.

We then can move on to building the HUD. We will place the construction of the HUD in its own script,  buildNurbsInfoHud.mel . The first thing we need to do is decide where on screen we want to place our information. Although we have 10 sectors from which to choose, we will add this HUD to the same one that contains the polygonal information, sector 0. In Example 11.39, we begin by issuing our four headsUpDisplay commands.

Example 11.39: Each line of our HUD requires a separate command.

 global proc buildNurbsInfoHud ()     {  // to allow for easy manipulation of HUD placement  int $HUDSection = 0;     headsUpDisplay         -section $HUDSection         -block 0         -blockSize "small"         -label "Spans U"         -labelFontSize "small"         -labelWidth 100         -command "nurbsInfo 0"         -event "SelectionChanged"         -nodeChanges "attributeChange"         niHUDSpanU;     headsUpDisplay         -section $HUDSection         -block 1         -blockSize "small"         -label "Spans V"         -labelFontSize "small"         -labelWidth 100         -command "nurbsInfo 1"         -event "SelectionChanged"         -nodeChanges "attributeChange"         niHUDSpanV;     headsUpDisplay         -section $HUDSection         -block 2         -blockSize "small"         -label "Divisions U"         -labelFontSize "small"         -labelWidth 100         -command "nurbsInfo 2"         -event "SelectionChanged"         -nodeChanges "attributeChange"         niHUDDivU;     headsUpDisplay         -section $HUDSection         -block 3         -blockSize "small"         -label "Divisions V"         -labelFontSize "small"         -labelWidth 100         -command "nurbsInfo 3"         -event "SelectionChanged"         -nodeChanges "attributeChange"         niHUDDivV;     } 
Note  

 nurbsInfo.mel needs to be copied into the active script path directory before the Heads-Up Display project functions correctly.

On the CD  

The text for this script is found on the companion CD-ROM as Chapter_11/project_UI08/v01/buildNurbsInfoHud.mel.

The results from this are seen in Figure 11.37, with a simple NURBs patch selected.

click to expand
Figure 11.37: Our NURBs HUD.

While this does work if there are no other HUDs active and occupying HUD sector 0, we can start running into problems when other HUDs attempt to occupy the same location. Therefore, we must build a script to find whether there are any HUDs already in existence and what their current screen position is. We will construct this as a separate procedure, and because this could be useful for the construction of other HUDs as well, we will make it a separate script. We begin in Example 11.40 by declaring the procedure, which will return an integer representing the next open block. We also want to pass it an integer representing the HUD sector we want to examine, as well as how many blocks we need.

Example 11.40: The procedure to find the next empty HUD block.

 global proc int getNextHudBlock (int $HUDSection,                                         int $blocksNeeded)     {  // get all HUDs  string $allHUDs[] = `headsUpDisplay                                 -lh`;     string $blockContents[];     int $returnInt;  // parse the list of HUDS  for($eachHUD in $allHUDs)         {  // find out which section this HUD is in  int $thisHUDSection = `headsUpDisplay                                     -query                                     -section                                     $eachHUD`;  // If it is in the target section  if ($thisHUDSection == $HUDSection)             {             int $block = `headsUpDisplay                                 -query                                 -block                                 $eachHUD`             $blockContents[$block] = $eachHUD;             }         }     int $found, $i;     while ($found == 0)         {         if ($blockContents[$i] == "")              for ($n = $i;$n < ($i + $blocksNeeded);$n++)                 if ($blockContents[$n] == "")                     {                     $returnInt = $i;                     $found = 1;                     }         }     return $returnInt;     } 
On the CD  

The text for this script is found on the CD-ROM as bonusscripts/getNextHudBlock.mel.

Now, we can call getNextHudBlock from within the procedure creating the NURBs HUD to get the first empty block that has three empty blocks after it. Sometimes a script will simply look for the next available open block, but this doesn t take into account the possibility of intermediary blocks being occupied, and if we want to have all our HUD elements contiguous, we have to look for a block of blocks. In Example 11.41 we see the HUD display procedure with both the block searching call in place, as well as if statements that turn the display of the HUD on or off, depending on the current state of the HUD.

Example 11.41: The addition of the call to the getNextHudBlock procedure.

 global proc buildNurbsInfoHud ()     {  // to allow for easy manipulation of HUD placement  int $HUDSection = 0;     int $block = `getNextHudBlock $HUDSection 4`;     if(`headsUpDisplay -exists niHUDSpanU` != 1)         headsUpDisplay             -section $HUDSection             -block $block++             -blockSize "small"             -label "Spans U"             -labelFontSize "small"             -labelWidth 100             -command "nurbsInfo 0"             -event "SelectionChanged"             -nodeChanges "attributeChange"             niHUDSpanU;     if(`headsUpDisplay -exists niHUDSpanV` != 1)         headsUpDisplay             -section $HUDSection             -block $block++             -blockSize "small"             -label "Spans V"             -labelFontSize "small"             -labelWidth 100             -command "nurbsInfo 1"             -event "SelectionChanged"             -nodeChanges "attributeChange"             niHUDSpanV;     if(`headsUpDisplay -exists niHUDDivU` != 1)         headsUpDisplay             -section $HUDSection             -block $block++             -blockSize "small"             -label "Divisions U"             -labelFontSize "small"             -labelWidth 100             -command "nurbsInfo 2"             -event "SelectionChanged"             -nodeChanges "attributeChange"             niHUDDivU;     if(`headsUpDisplay -exists niHUDDivV` != 1)         headsUpDisplay             -section $HUDSection             -block $block++             -blockSize "small"             -label "Divisions V"             -labelFontSize "small"             -labelWidth 100             -command "nurbsInfo 3"             -event "SelectionChanged"             -nodeChanges "attributeChange"             niHUDDivV;     if (`headsUpDisplay                 query                 visible                 niHUDSpanU`                 == 0)         headsUpDisplay edi visible 1 niHUDSpanU;     else         headsUpDisplay edi visible 0 niHUDSpanU     if (`headsUpDisplay                 query                 visible                 niHUDSpanU`                 == 0)         headsUpDisplay edi visible 1 niHUDSpanU;     else         headsUpDisplay edi visible 0 niHUDSpanU     if (`headsUpDisplay                 query                 visible                 niHUDSpanU`                 == 0)         headsUpDisplay edi visible 1 niHUDSpanU;     else         headsUpDisplay edi visible 0 niHUDSpanU     if (`headsUpDisplay                 query                 visible                 niHUDSpanU`                 == 0)         headsUpDisplay edi visible 1 niHUDSpanU;     else         headsUpDisplay edi visible 0 niHUDSpanU     } 
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_11/project_UI08/final/buildNurbsInfoHud.mel.




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