• No results found

Running a Script

In document Sybex - Maya. Secrets of the Pros (Page 195-199)

To run any script In this chapter, follow these steps:

1. Type the two following lines in Maya Script Editor, opportunely customized for your needs:

s o u r c e " m y P a t h / m y S c r i p t . m e l " ; m y P r o c G U I ;

You want to run the myProcGUI procedure from the file m y S c r i p t . m e l .

2. MM+select both lines, and drag and drop them on a shelf. A new MEL icon becomes available.

3. Simply click the icon to run the script. A small prompt window will pop-up requesting your inputs.

As I mentioned, varying one or more colors of a character doesn't mean replacing an existing color with another randomly chosen color. Often the art department chooses the colors, and you are allowed to change them only slightly. In other cases, colors can be quite different from one another but must be chosen from a precise color palette.

A third possibility, sometimes overlapping with the first, allows for wild variations, but requires that one color maintain the "chromatic distance" between the hues of the various col-ors (see Figure 6.5).

For example, if one of the colors is a dark orange (hue 20), and another is a bright green (hue 100), a shift of +80 to both of them will maintain the chromatic distance, turning the first color to a bright green (hue 20 + 80 = 100) and the second to a bright cyan (hue 100 + 80 = 180).

If you choose the starting colors properly, any parallel random shift in the hue gener-ates an equally nice and rich combination. For example, try to change our Zoid's three pri-mary colors, manually modifying the shader tree in the file Z o i d _ b a s e . m b , and test different starting combinations, such as two colors relatively close, say, two shades of purple, and a complementary one, a yellow.

The script has two main working modes: absolute and relative. If a number is the first parameter, the mode is absolute. In this case, the new hue will be generated choosing a random value in a numeric range centered on the first parameter and sized by the second.

For example, if the first parameter is 100 and the second is 0, the random range is col-lapsed to a single number. Therefore, all Zoids will have the same color, a bright green (hue 100). If, instead, we use a size of 180, the range is +180 centered on 100, covering the entire hue cyclic spectrum (0-360), guaranteeing the wildest color variations.

If the word "rel" is the first parameter instead of a number, the size of the random range is defined by the second parameter as in the earlier case, but the center of the range

180 C H A P T E R 6 • Creating Crowd Scenes from a Small Number of Base Models

retains the hue of the Zoid cur-rently being processed by the script's main loop. Therefore, if the Zoid is yellow (hue 60) and a range size of 60 is allowed, in the two extreme cases, the Zoid main color becomes red (hue 60-60=0) or green (hue 60+60=120), while another Zoid with a different color will have different extremes (see Figures 6.6 and 6.7).

No mode is better than the other in this script; they're simply different. If you need only small variations of a precise color, use the precise hue of that color, and then keep the range size small. The relative mode might be the right choice if you have, for example, two groups of Zoids, one in orange and the other in blue, and you want to make the individuals slightly different without shifting too much from the color they have already. The relative mode and a small-sized range will keep them mainly orange or blue, but the different shades of those two colors will make the individuals different and yet of two distinctive groups.

The final input parameters allow us to choose the color affected by the script. Each Zoid has three colors: the main one, by default blue; the yellow spots pattern; and the red fake rim light. Typing the keywords "main," "pattern," and "rim" separated by spaces affects all three colors. Although their hues are different, their random shift on the color wheel will be uniform in any case (You can change this behavior by uncommenting lines 70, 102, and 134 and commenting the line immediately following each of them.) The use of the single word "all" has the same effect. Any subgroup or even just one of the colors can be affected. You can decide, for example, that you want to keep the default yellow color for the spots pattern, but allow both main color and rim to change slightly. Or maybe you just hate the red rim light, and you want to change it to different shades of green. Simply type one of the keywords "main," "pattern," or "rim" to tell the script which color should be affected.

Figure 6.5: The RGB color wheel: two colors keep their reciprocal chromatic distance if the distance between their hue values does not change.

6.6: Wild co/or variations—Input values: rel 180 all Figure 6.7: Subtler color variations—Input values: rel 60 all

A few changes to the script Z o i d _ h u e V a r . m e l can lead to two additional scripts, one varying the saturation and the other varying the value of the colors. Only one difference must be taken into account: hue is cyclic, meaning that a hue of 360 is the same red as hue 0. Instead, both saturation and value have little meaning out of the 0.0-1.0 range, often generating artifacts and unwanted effects when pushed beyond those limits. You must consider this when generat-ing new colors, eventually clampgenerat-ing the result to fit in this range.

Size and Proportions

Color can undoubtedly differentiate characters, but so can shape. In real life, size and shape are a great ways to tell the difference between individuals in a crowd. Although animals in the same species tend to look alike to the untrained eye, most people can quickly pick up even subtle differences in size and proportions between two human (or humanlike) figures.

The purpose of the script Z o i c L s i z e V a r . m e l (on the CD-ROM) is to create size and proportion differences in the Zoid models. Mostly acting on the bones of the character skele-ton, the script changes the proportions of the limbs, torso, and head in a limited, cartoon-ish—but reasonable—manner (see the results in Figure 6.8).

You can test this script with the Maya file Z o i d _ 1 6 a r r _ s i z e . m a on the CD-ROM.

Most of the parameters for these changes are internal to the script; there are too many of them for the simple interface I had the time to develop. The only input the user needs to provide is the minScale and maxScale, loosely defining the final height range of the Zoids. A

182 C H A P T E R 6 • Creating Crowd Scenes from a Small Number of Base Models

plethora of things happen in the script though. First, the length of the Zoid skeleton is modi-fied. He gets taller or shorter, the ratio between the length of his legs and the height of his torso are modified, and the length of his arms is changed. Although some variations are allowed, a general rule hard-coded in the script is that the length of the limbs is proportional to the height scaling factor of the Zoid. This rule guarantees that a tall Zoid will have decently long arms and that a small Zoid will have shorter arms. For instance, the formula behind the scaling of the arms is the following simple one from line 60 of the script:

$ a r m s L e n g t h = ( ' r a n d 0 . 9 1.2' * $ r n d H e i g h t ) ;

Here $ r n d H e i g h t is the overall random height scaling factor. As you can see, a random number is involved, to make sure that two similarly tall Zoids won't necessarily have the same arm lengths, but the final number is also connected to the Y scaling of the character. Y scaling, however, is not the simple scaling value of the Zoid's top transform node. You can scale the character only by changing the scale attributes of its joints, and the overall height is actually a composite of the length scaling of the legs and torso joints. This makes the object space uniform from Zoid to Zoid, allowing for easier debugging of the script's simple math in case of weird results. Additionally and more important, a nonproportional scaling of the character's top node, say «1.0, 2.0, 2.0», would lead to warping of the joints and the over-lying skin, an effect not immediately noticeable if the character is in the neutral position, but easy to spot as soon as there's a left/right or forward/backward tilt of head and torso.

In the phase I just described, legs and arm joints are scaled proportionally on all their axes. This process is quite similar to scaling the top node, which generates a proportionate character, simply bigger or smaller. At this point, the script forks in three possible flows, through the long If block between lines 109 and 197.

In 30 percent of the cases, nothing happens. The Zoid you now have is what you'll see in the scene, and no further changes are made to its bone structure.

In 35 percent of the cases, you'll get a strong Zoid. The thick-ness of legs, torso, and arms is increased, basically through simple change on the Scale Y and Scale Z attribute of each joint. The X scaling, or length of the joint, is untouched. The result is usually a rather muscular Zoid.

In the remaining 35 percent of the cases, the thickness of the limbs and torso do change, just in the opposite direction, generating thin, skinny Zoids.

These percentages and scaling values embedded in the code are a matter of personal taste and testing.

They do not have a particular logic other than that the arms shouldn't get long enough to touch the ground level. How much distortion Figure 6.8: An example of the variations generated by the

scnipt Z o i d _ s i z e V a r . m e l on the scene Z o i d _ 1 6 a r r _ s i z e . m a — l n p u t v a l u e s 0.8 and 1.25

the same animation used for many similar but never identical characters.

In document Sybex - Maya. Secrets of the Pros (Page 195-199)