|
|||||||||
We also used many functions. Since the rotation of the fingers will occur similarly in all fingers with three links, using functions makes the script easier and faster. We dont need to repeat all the code everywhere; we just use the functions and define the correct parameters. One interesting feature we added to the script is the Invert button. This allows the user to re-use this hand as a left or a right hand, or even to add some strange movements to the hand. Feel free to modify this script and add other features. Building Shortcut MenusIts true in MAX as it is in so many programs: shortcut menus are very useful. (In case you do not know, MAXs shortcut menus are scripts.) Besides right-clicking an object, we can also Ctrl+right-click it, and a new menu will appear. This menu is called the Custom shortcut menu. We can customize both shortcut menus, but lets avoid working in the regular one. Lets work with the Custom menu instead. To edit it, Ctrl+right-click any place in the screen and choose Customize Menu. Shortcut menus are made of three parts: filters, menu items, and actions. The filters will be used to allow us to see different menu options depending on which object is selected. For instance, locate the Filter Functions and add: fn anyoneselected = (selection.count > 0) This filter will return true if theres any object selected. If there isnt, it will hide the menu lines associated with it. Now lets add some menu options. Under menuitem mi_isolate Isolate Tools, add and evaluate: separator Sep_custom00 filter:anyoneselected submenu Render Properties ON filter:anyoneselected ( menuitem mi_renderable_on Renderable menuitem mi_Cast_Shadows_on Cast_Shadows menuitem mi_Receive_on Receive Shadows menuitem mi_Inherit_on Inherit Visibility separator sep_rend_prop menuitem mi_All_on All On ) Weve created a horizontal line that will divide the shortcut menu in sections using SEPARATOR. (Some scripts use SEPERATOR; MAX allows this spelling.) Notice that this line has a filter, which makes the line appear only when theres an object selected. Next we created a submenu. The submenu opens another menu to the right with several options. This submenu is also filtered, so it only appears when at least one object is selected. Then we added the menu options, using MENUITEM. Notice we didnt need to add a filter to them, because we already have filtered the submenu. Lets add the actions for these menus. Locate on mi_render picked and add the following code before it: on mi_renderable_on picked do ( for i in 1 to selection.count do selection[i].renderable = true ) on mi_Cast_Shadows_on picked do ( for i in 1 to selection.count do selection[i].castshadows = true ) on mi_Receive_on picked do ( for i in 1 to selection.count do selection[i].receiveshadows = true ) on mi_inherit_on picked do ( for i in 1 to selection.count do selection[i].inheritvisibility = true ) on mi_All_on picked do ( for i in 1 to selection.count do ( selection[i].renderable = true selection[i].castshadows = true selection[i].receiveshadows = true selection[i].inheritvisibility = true ) ) These commands are the actions that are executed when the specified menu item is picked. Notice we always used for i in 1 to selection.count, since we do not know how many objects will be selected. This makes the script work in all situations. Doing this, we can add any property to the shortcut menu. Check the Rcmenu.ms file (the name stands for right-click menu) located in the stdplugs\scripts folder. It has many more options and commands. Make sure you save a backup file before editing them. SummaryAdding a user interface to a script is essential to making it interactive and easy to use. This chapter laid out the most important techniques to include UIs with your scripts. Make sure you have in mind all the features you want in your script before starting. Some people prefer to start from the UI, some prefer to start from the engine of the script (the actions). Do it the way you feel comfortable, but it will be easier to build the code if you think out the requirements first, creating a storyboard of the script the same way that moviemakers do. In Chapter 16 youll learn how to use MAXScript with keyframes, controllers, and everything related to animation.
© 2000, Frol (selection, edition, publication) |
|||||||||
|