|
|||||||||||||||||||||||||||||
Each material has a series of properties, which can be listed by the SHOWPROPERTIES command. For instance, type m = standardmaterial(). Now use showproperties m. You will see all properties of this material.
Defining Colors The first thing you need to adjust in a material is the color. Colors in MAXScript are defined using a point3 variable just like position or scale. You can define any color in any material using material.color = [red,green, blue]. The property will vary depending on which color will be defined. Using the example above, youd set the diffuse color to red with m.diffusecolor = [255,0,0]. Defining Shaders In MAX, materials can be made using different shaders. Each shader will define a series of properties to the material. You can define the shader using two different properties: .shadertype, which will require an index number of the shader; or .shaderbyname, which will require a string with the name of the shader. Figures 4.5 and 4.6 show examples of two different shaders.
Using the same example you used above, lets set a different shader and some properties. Type m.shaderbyname = Strauss.
Working with Maps in MaterialsBesides working with materials, you also need to work with maps. MAXScript can access any information within any map in MAX. Lets look at some maps and how can you work with them in the materials. Texture Maps The first, and possibly the most used, map you will see is the bitmap. To create a bitmap you simply use variable = bitmaptexture(). Since it works the same way as .standardmaterial(), you can assign it directly to the material, for instance m = standardmaterial() m.diffusemap = bitmaptexture() Using SHOWPROPERTIES you can list all options in a bitmap. The most important one, and possibly the most used one, is .filename, which allows you to assign a filename to the bitmap.
Using SELECTSAVEBITMAP to Script User Interaction Its very difficult to memorize filenames and paths. Fortunately, you can use a MAX-Script command, SELECTSAVEBITMAP, that will ask the user to select a file and will assign the complete path to a variable. When executed, this command displays a dialog box asking the user to select a bitmap to be saved (Figure 14.7).
You can use it to assign a bitmap file directly to a texture map, like this: bmp = bitmaptexture() bmp.filename = selectsavebitmap() Showing a Map in a Viewport It would be nice if the bitmap had an option to show the map in the viewport, but it works differently, because one material cant have more than one map displayed in the viewport. Enabling one map automatically disables the other. To enable a map in viewport, you should use SHOWTEXTUREMAP, which will require you to specify the material and the map that will be shown. Using the examples above, you would have showtexturemap m bmp on Material EditorIn MAX, all the work done with materials happens in the Material Editor. In MAXScript, you usually can use the Material Editor to place one material as a way to show it to the user. MAXScript has several commands to read or display a material in any of the Material Editor slots. Reading Materials You can read one material from any of the 24 slots of the Material Editor. This can be done using GETMEDITMATERIAL. You also can use MEDITMATERIALS[index], where index will represent the number of the slot you want to access. For instance, if you want to assign the material in the first slot to the selected objects, you can use either of these lines: $.material = meditmaterials[1] $.material = getmeditmaterial 1 Displaying Materials in the Material Editor To display any material in the Material Editor, use the opposite process from reading a material. You can use either SETMEDITMATERIAL or MEDITMATERIAL[index]. For instance, if you want to set the first material editors slot with the material of the selected object, you can use either of these lines: meditmaterials[1] = $.material setmeditmaterial 1 $.material Material LibrariesMAXScript can access the current material library or any other material library as an array of materials. CURRENTMATERIALLIBRARY returns all materials in the current library indexed as an array. Since it is an array, you can use append to add materials to the library. You can also use currentmateriallibrary.count to know how many materials are in the library, and currentmateriallibrary[index] to read any material from the library. You can use LOADMATERIALLIBRARY and SAVEMATERIALLIBRARY to load and save the current material library. These two commands will require you to specify a filename string to load or save the file.
If you do not know the name and path of the material library, you can use FILE-OPENMATLIB, FILESAVEMATLIB, and FILESAVEASMATLIB to display a dialog box where you can choose the material library file to open or save, as shown in Figure 14.8.
Other Materials and MapsMAXScript allows you to create and manipulate all materials and maps. Each one has different options, and different sub-materials or maps. For instance, the Multi/ Sub-Object material is created in MAXScript using MULTIMATERIAL, and since it is made of sub-materials, you can access each of them as an array index, using multimaterial[index]. Some maps, like composite, mix, and mask, also require sub-maps and work either using an array variable, or through the different map options.
© 2000, Frol (selection, edition, publication) |
|||||||||||||||||||||||||||||
|