|
|||||||||||||
Recording MaterialsThe Macro Recorder can record all options in one material or map, when you work with them in the Material Editor. You can use it to help you create materials in scripts, which will save you a lot of time. The actions are recorded based on the selected slot in the Material Editor. Setting the diffuse color creates, for instance, meditMaterials[1].diffuse = color 50 149 181 This line must now be adjusted in your script, manipulating the material you want. For instance, if this material belongs to a specific object named box you should use $box.material.diffuse = color 50 149 181 If you want to manipulate the current objects material, you can read it in the Material Editor, using the Pick Material from Object button, and then manipulate the material using the Recorder. At the end, you can set the material to the object again using the Assign Material to Selection button. Hands-On MAXScript: Adding a Noise Bump Map to a MaterialIn this exercise you will make a script that adds a noise bump map to an objects material and then make some adjustments in the material. This script will read the material of the selected object, change the shader to Oren-Nayar-Blinn, and then add the noise map to the bump map. The script also will ask the user how much bump they want. At the end, you will create a Macro Script of it, and assign it to a button in any toolbar. Start a new script and type these commands (or open the file bump_exercise.ms on the CD-ROM): if selection.count == 0 then format “Select an object first.” else if selection.count > 1 then format “Select a single object only.” else ( obj = $ if obj.material == undefined then format “Selected object has no material \ applied.\n” else ( meditmaterials[1] = obj.material
What you did here was test how many objects were selected, and warn the user that one and only one object must be selected. Then, if only one object was selected, you checked to see if it had a material applied. If so, the script copies this material to the first Material Editor slot. Now turn on the Macro Recorder and edit the following values in the material:
This is the result of what was recorded: meditMaterials[1].shaderType = 4 meditMaterials[1].adTextureLock = on meditMaterials[1].adTextureLock = on meditMaterials[1].diffuseRoughness = 30 meditMaterials[1].specularLevel = 43 meditMaterials[1].glossiness = 35 meditMaterials[1].Soften = 0.5 meditMaterials[1].bumpMapAmount = 40 meditMaterials[1].bumpMap = Noise () meditMaterials[1].bumpMap.size = 15 Lets add the user interaction part to the script, continuing the script you started: bump_amount = getkbvalue prompt:”Enter Bump amount: “ bump_size = getkbvalue prompt:”Enter Bump size: “ Copy the recorded lines to the script, and edit the following lines: meditMaterials[1].bumpMapAmount = bump_amount meditMaterials[1].bumpMap.size = bump_size Remember to close the two parentheses that were opened, and the script is ready! If you want, you can drag it to the toolbar and create a Macro Script button. Also remember that the Listener must be opened, so the user can type the values requested with GETKBVALUE. (Unfortunately, the Mini-Listener does not work in instances like this.) Listing 14.2 is the final complete script.
LISTING 14.2: The Noise Bump Map script (bump_exercise.ms) if selection.count == 0 then format “Select an object first.\n” else if selection.count > 1 then format “Select a single object only.\n” else ( obj = $ if obj.material == undefined then format “Selected object has no material \ applied.\n” else ( meditMaterials[1] = obj.material bump_amount = getkbvalue prompt:”Enter Bump amount: “ bump_size = getkbvalue prompt:”Enter Bump size: “ meditMaterials[1].shaderType = 4 meditMaterials[1].diffuseRoughness = 30 meditMaterials[1].specularLevel = 43 meditMaterials[1].glossiness = 35 meditMaterials[1].Soften = 0.5 meditMaterials[1].bumpMapAmount = bump_amount meditMaterials[1].bumpMap = Noise () meditMaterials[1].bumpMap.size = bump_size ) ) Working with Modifiers and Modifier OptionsModifiers are essential for modeling in MAX. You also need modifiers for material and surfaces manipulation. In this section you will look at how to add modifiers and use modifier options. Adding ModifiersYou can add a modifier to any MAX object, if the modifier respects the object type. For instance, you can add a Bend modifier to a cylinder. First, create a cylinder using c = cylinder height:60 radius:12 heightsegs:15 Then add the bend using addmodifier c (bend()). Notice the () after bend. This is because we have no parameters assigned to the modifier. If we wanted, we could directly specify the angle, using addmodifier c (bend angle:30). If the modifier added to the object is not compatible, MAX will return an error message. You can check the objects class to see if its compatible with the modifier, or you can use the VALIDMODIFIER command, which will return true if the modifier can be added to the object. Using the cylinder above, you could check to see whether it allows you to use the Normalize Spline modifier by means of validmodifier $ (normalize_spline()) Using Modifier OptionsThe modifier options are accessed the same way you access all properties in MAXScript. Continuing to use the cylinder example, you can see the properties of the bend modifier by using showproperties c.bend. You can then change the angle of the bend with c.bend.angle = value, as in Figure 14.9.
You can access any property of any modifier this way. Some modifier values are check boxes, which will be enabled or not. In MAXScript, these usually use true (on) or false (off). When a modifier has radio buttons, the value exposed is an integer, where the number will specify which of the buttons is active. Global OptionsA modifier can be enabled or disabled, either globally or in the viewports only. You can also change its name, and even remove the modifier or collapse the stack. These properties are global to all modifiers.
© 2000, Frol (selection, edition, publication) |
|||||||||||||
|